Pointer Interactions

Panther·2021년 8월 4일
0

https://developer.apple.com/documentation/uikit/pointer_interactions

"Support pointer interactions in your custom controls and views."

커스텀 컨트롤 및 뷰에서 포인터 상호작용을 지원합니다.

Overview

iPadOS 13.4는 트랙패드, 마우스와 같은 외부 입력 장치 사용의 경험을 강화하고자 동적 포인터 효과 및 동작을 제공합니다. 사람들이 입력 장치를 사용할 때, iPadOS는 포인터를 현재 맥락에 자동으로 적용시켜, 생산성 향상과 작업 수행의 단순화에 필요한 시각적 피드백 및 정확도 수준 개선을 제공합니다.

UIKitUIbutton, UIBarButtonItem, UISegmentedControl을 사용하는 경우 자동으로 포인터 상호작용을 처리합니다. 만약 컨텐트 표시를 위해 커스텀 뷰를 사용하고 있다면, 포인터 효과 및 스타일을 직접 정의해야 합니다.

더 많은 정보는 Pointers (iPadOS)를 살펴보시기 바랍니다.

Pointers (iPadOS)
https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/pointers/

Custom Pointer Styles

뷰에 커스텀 포인터 스타일 효과를 추가하려면 아래 단계를 수행해야 합니다.

  1. UIPointerInteraction 인스턴스를 생성합니다.
  2. 포인터 상호작용의 딜리게이트(UIPointerInteractionDelegate 프로토콜을 따르는 객체)를 구체화합니다.
  3. 뷰의 상호작용 속성에 상호작용을 추가합니다.
  4. pointerInteraction(_:styleFor:) 딜리게이트 메소드를 추가합니다.
  5. 해당 딜리게이트 메소드로부터 UIPointerStyle를 반환합니다.

이 예시는 일반적인 경우처럼 뷰 컨트롤러의 viewDidLoad() 메소드 내부에서 호출하는 방식으로 커스텀 헬퍼 메소드를 사용한 예시입니다.

func customPointerInteraction(on view: UIView, pointerInteractionDelegate: UIPointerInteractionDelegate) {
    let pointerInteraction = UIPointerInteraction(delegate: pointerInteractionDelegate)
    view.addInteraction(pointerInteraction)
}

pointerInteraction(_:styleFor:) 딜리게이트 메소드는 포인터가 뷰의 영역에 진입할 때 호출됩니다. 아래 예시는 UIPointerStyle 객체를 반환함으로써 UIPointerLiftEffect 효과를 적용하는 상호작용을 보여주고 있습니다.

    func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
        var pointerStyle: UIPointerStyle? = nil

        if let interactionView = interaction.view {
            let targetedPreview = UITargetedPreview(view: interactionView)
            pointerStyle = UIPointerStyle(effect: UIPointerEffect.lift(targetedPreview))
        }
        return pointerStyle
    }

Interaction Animations

애니메이션을 포함시키는 것은 포인터 상호작용에서 유용하며, 특히 뷰가 포인터 효과를 방해하는 요소를 포함하고 있는 경우에 더욱 그렇습니다. 예를 들어 포인터가 UISegmentedControl에 진입할 때 UISegmentedControl에서 분리 바를 숨기는 것은 활성화된 세그멘트 효과가 시각적으로 깔끔하게 나타나도록 해줍니다. 아래 예시는 포인터가 영역에 진입 혹은 빠져나올 때 뷰의 알파 값을 변경시켜 간단한 애니메이션을 수행하게 하는 예시입니다.

    func pointerInteraction(_ interaction: UIPointerInteraction, willEnter region: UIPointerRegion, animator: UIPointerInteractionAnimating) {
        if let interactionView = interaction.view {
            animator.addAnimations {
                interactionView.alpha = 0.5
            }
        }
    }

    func pointerInteraction(_ interaction: UIPointerInteraction, willExit region: UIPointerRegion, animator: UIPointerInteractionAnimating) {
        if let interactionView = interaction.view {
            animator.addAnimations {
                interactionView.alpha = 1.0
            }
        }
    }

Pointing Device Touch Responses

만약 포인팅 기기 터치 이벤트와 다른 소스로부터의 터치 이벤트를 구분하고 싶다면(사용자의 손가락이나 애플 펜슬과 같은), Info.plist 파일에서 UIApplicationSupportsIndirectInputEvents 키를 활성화할 수 있습니다. 이 키를 활성화하면 앱은 UITouch.TouchType.indirectPointer의 터치가 목표하고 있는 특정 제스쳐에 응답할 수 있습니다. 더 자세한 내용은 UIApplicationSupportsIndirectInputEvents를 살펴보시기 바랍니다.

UIApplicationSupportsIndirectInputEvents
https://developer.apple.com/documentation/bundleresources/information_property_list/uiapplicationsupportsindirectinputevents

Topics


Essential

UIPointerInteraction

앱의 영역 내에서 뷰에 대한 효과를 지원 가능하게 하거나 포인터의 모양을 커스터마이즈 하는 것을 가능하게 하는 상호작용입니다.

https://developer.apple.com/documentation/uikit/uipointerinteraction
https://velog.io/@panther222128/UIPointerInteraction


Pointer Styles

UIPointerStyle

포인터 모양과 효과를 정의하는 객체입니다.

https://developer.apple.com/documentation/uikit/uipointerstyle
https://velog.io/@panther222128/UIPointerStyle

UIPointerAccessory

베타이기 때문에 오버뷰 사용이 불가능합니다.

https://developer.apple.com/documentation/uikit/uipointeraccessory
https://velog.io/@panther222128/UIPointerAccessory


Pointer Region

UIPointerRegion

포인터 움직임과 상호작용하는 사각형 영역입니다.

https://developer.apple.com/documentation/uikit/uipointerregion
https://velog.io/@panther222128/UIPointerRegion

UIPointerRegionRequest

상호작용의 뷰에서 포인터의 위치를 설명하는 객체입니다.

https://developer.apple.com/documentation/uikit/uipointerregionrequest
https://velog.io/@panther222128/UIPointerRegionRequest


Lock State

UIPointerLockState

씬의 포인터 잠금 상태에 대한 정보를 포함하는 객체입니다.

https://developer.apple.com/documentation/uikit/uipointerlockstate
https://velog.io/@panther222128/UIPointerLockState


See Also


User Interactions

Touches, Presses, and Gestures

제스쳐 리코그나이저에 있는 앱의 이벤트 처리 로직을 캡슐화함으로써 앱에서 해당 코드를 재사용할 수 있게 합니다.

https://developer.apple.com/documentation/uikit/touches_presses_and_gestures
https://velog.io/@panther222128/Touches-Presses-and-Gestures

Drag and Drop

뷰에서 상호작용 API를 사용해 앱으로 드래그 앤 드롭 기능을 가져옵니다.

https://developer.apple.com/documentation/uikit/drag_and_drop
https://velog.io/@panther222128/Drag-and-Drop

Pencil Interactions

애플 펜슬을 사용해 더블 탭 사용자 상호작용을 처리합니다.

https://developer.apple.com/documentation/uikit/pencil_interactions
https://velog.io/@panther222128/Pencil-Interactions

Focus-Based Navigation

원격, 게임 컨트롤러, 키보드를 사용해 UIKit 앱의 인터페이스를 탐색합니다.

https://developer.apple.com/documentation/uikit/focus-based_navigation
https://velog.io/@panther222128/Focus-Based-Navigation

메뉴 시스템, contextual 메뉴, 홈 스크린 퀵 액션, 키보드 단축키를 사용해 앱과의 상호작용을 단순화합니다.

https://developer.apple.com/documentation/uikit/menus_and_shortcuts
https://velog.io/@panther222128/Menus-and-Shortcuts

Accessibility for UIKit

UIKit 앱을 iOS 및 tvOS를 사용하는 모두에게 접근 가능한 형태로 만듭니다.

https://developer.apple.com/documentation/uikit/accessibility_for_uikit
https://velog.io/@panther222128/Accessibility-for-UIKit


0개의 댓글