自定義轉場動畫展現PopView

jopen 9年前發布 | 8K 次閱讀 PopView iOS開發 移動開發

PopView

自定義轉場動畫展現PopView

介紹:

這種效果類似微信右上角的彈窗,但不同的是,PopView加了轉場動畫,這樣看上去更酷一點.

微信的長這個樣子

我的目前看起來是這個樣子

用法:

1.將Resource文件夾拖入到工程中

2.點擊事件通知的添加和移除

 override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "didClickedFirstCell", name: DidClickedPopViewCell1Noti, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "didClickedSecondCell", name: DidClickedPopViewCell2Noti, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "didClickedThirdCell", name: DidClickedPopViewCell3Noti, object: nil)

}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    NSNotificationCenter.defaultCenter().removeObserver(self)
}

3.點擊事件的實現
 func didClickedFirstCell(){
    // modal/push Other Controller
    print(__FUNCTION__)
}

func didClickedSecondCell(){
    print(__FUNCTION__)
}

func didClickedThirdCell(){
    print(__FUNCTION__)
}

4.聲明轉場動畫代理
@IBAction func didClickedLeftButton() {
    modalPopView(PopViewType.Left)
}

@IBAction func didClickedCenterButton() {
    modalPopView(PopViewType.Center)
}


@IBAction func didClickeRightButton() {
    modalPopView(PopViewType.Right)
}

let animationDelegate = PopoverAnimation()

func modalPopView(type:PopViewType){
    let popVc = PopViewController()
    popVc.popType = type
    popVc.transitioningDelegate = animationDelegate
    animationDelegate.popViewType = type
    popVc.modalPresentationStyle = UIModalPresentationStyle.Custom
    presentViewController(popVc, animated: true, completion: nil)
}

}

聲明:

1.已適配3.5inch~5.5inch.
2.iOS8以上可用,iOS8以下沒測試過.
3.有問題隨時issue或者郵箱hdbphil@gmail聯系我.


項目主頁:http://www.baiduhome.net/lib/view/home/1449062444639

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!