iOS和Objective C中的循环过渡(掩码) [英] Circular transition (mask) in iOS and Objective C

查看:104
本文介绍了iOS和Objective C中的循环过渡(掩码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想知道如何使用新按钮轻松构建圆形蒙版,将背景混合并转换为新视图?请参阅此处的示例(观看红色星球被触发):

We were wondering how we can easily build a circular mask, that blends out the background and transitions into a new view, with new buttons? See example here (watch the red planet gets triggered):

推荐答案

// Swift 4

//Swift 4

这是一个简单的静态方法,用于从点屏幕转换圆形气泡。

This is a simple static method for circular bubble transition from a point screen.

//如此链接所示
https://github.com/andreamazz/BubbleTransition

    import UIKit

    class AnimationUtility: UIViewController {
        static func animateBubbleTrnsitionView( selfView: UIView, point : CGPoint) {
                //let button = CGRect.init(x: 30, y: selfView.frame.size.height - 15, width: 45, height: 45)
                let button = CGRect.init(x: point.x, y: point.y, width: 0, height: 0)

                let circleMaskPathInitial = UIBezierPath(ovalIn: CGRect.init(x: point.x, y: point.y, width: 1, height: 1))
                let extremePoint = CGPoint(x: point.x, y: 15 - selfView.frame.size.height - 200)
                let radius = sqrt((extremePoint.x*extremePoint.x) + (extremePoint.y*extremePoint.y))
                let circleMaskPathFinal = UIBezierPath(ovalIn: (button.insetBy(dx: -radius, dy: -radius)))

                let maskLayer = CAShapeLayer()
                maskLayer.path = circleMaskPathFinal.cgPath
                selfView.layer.mask = maskLayer

                let maskLayerAnimation = CABasicAnimation(keyPath: "path")
                maskLayerAnimation.fromValue = circleMaskPathInitial.cgPath
                maskLayerAnimation.toValue = circleMaskPathFinal.cgPath
                maskLayerAnimation.duration =  0.9
                maskLayer.add(maskLayerAnimation, forKey: "path")
            }
}

以下列方式使用此代码
执行segue或push w没有动画。

Use this code in following way Perform segue or push without animation.

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            // Get the new view controller using segue.destinationViewController.
            // Pass the selected object to the new view controller.
            switch segue.identifier! {
            case "navToHomeWithoutanimation":
                self.navigationController?.view.backgroundColor = APP_ORANGE_COLOR  //which ever color you want
                let vc = segue.destination as! MapViewController
                AnimationUtility.animateBubbleTrnsitionView(selfView: vc.view, point: self.view.center)
                break
    }
   }

//动画将从给定点开始动画。

//The animation will start to animate from given point.

这篇关于iOS和Objective C中的循环过渡(掩码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆