[swift] Swift Presentr를 사용한 앱의 게임화 방법

Swift Presentr

앱을 개발하다보면 사용자들에게 더욱 재미있는 경험을 제공하기 위해 게임화 요소를 추가하고 싶을 때가 있습니다. 이번 글에서는 Swift Presentr 라이브러리를 활용하여 앱에 게임화 요소를 추가하는 방법에 대해 알아보겠습니다.

Swift Presentr란?

Swift Presentr는 Swift로 작성된 앱에서 간편하게 커스텀 모달 표시창을 만들 수 있는 라이브러리입니다. Presentr을 사용하면 앱에 쉽게 다양한 효과와 애니메이션을 추가할 수 있습니다.

Swift Presentr 설치

Swift Presentr을 사용하기 위해 먼저 Cocoapods를 통해 라이브러리를 설치해야 합니다. Podfile 파일에 다음의 코드를 추가합니다.

pod 'Presentr'

설치가 완료되면, .xcworkspace 파일을 열어서 작업을 진행합니다.

Presentr 커스텀 표시창 생성

Presentr 라이브러리를 사용해 커스텀 표시창을 생성해 보겠습니다. 먼저, Presentr 객체를 생성하고 표시할 표시창의 속성들을 설정합니다.

import Presentr

let presenter: Presentr = {
    let width = ModalSize.full
    let height = ModalSize.fluid(percentage: 0.5)
    let center = ModalCenterPosition.center
    let customPresenter = Presentr(presentationType: .alert)
    customPresenter.presentationType = .popup
    customPresenter.transitionType = .coverVertical
    customPresenter.dismissTransitionType = .coverVerticalFromTop
    customPresenter.roundCorners = true
    customPresenter.backgroundColor = .black
    customPresenter.backgroundOpacity = 0.5
    customPresenter.dismissOnSwipe = true
    customPresenter.dismissOnTap = true
    
    customPresenter.dismissAnimated = true
    customPresenter.roundCornersRadius = 10
    customPresenter.blurBackground = true
    customPresenter.blurStyle = .light
    return customPresenter
}()

위의 코드에서 let customPresenter = Presentr(presentationType: .alert) 부분에서 표시창의 종류를 설정합니다. .alert 대신 .popup 등의 다른 종류를 지정할 수 있습니다. 또한, 다양한 설정들을 이용해 원하는 효과와 디자인을 적용할 수 있습니다.

Presentr 표시창 호출

표시창을 호출하기 위해 Presentr을 사용하는 방법은 간단합니다. 아래의 예제를 참고해보세요.

let viewControllerToPresent = YourCustomViewController(nibName: "YourCustomViewController", bundle: nil)
present(viewControllerToPresent, animated: true, completion: nil)

결론

Swift Presentr을 사용하면 앱에 다양한 게임화 요소를 추가할 수 있습니다. 우리는 Presentr을 사용해서 커스텀 모달 표시창을 만들고 호출하는 방법에 대해 알아보았습니다. Presentr의 다양한 설정을 통해 원하는 디자인과 효과를 적용할 수 있으니, 창의적인 아이디어를 구현해보세요!

참고 자료