新しいボタンを使用して、背景とトランジションを新しいビューにブレンドする円形マスクを簡単に作成するにはどうすればよいでしょうか? ここで例を参照してください (赤い惑星がトリガーされるのを見てください):
1557 次
2 に答える
0
スウィフトコード :
すべてのコード appdelegate ファイルを作成しました。本格的な UITableView ではなく、タイムラインのスクリーンショットを使用しました。
まず、ウィンドウにスクリーンショットを追加しましょう。
let imageView = UIImageView(frame: self.window!.frame)
imageView.image = UIImage(named: "twitterscreen")
self.window!.addSubview(imageView)
self.mask = CALayer()
self.mask!.contents = UIImage(named: "twitter logo mask").CGImage
self.mask!.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
self.mask!.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.mask!.position = CGPoint(x: imageView.frame.size.width/2, y: imageView.frame.size.height/2)
imageView.layer.mask = mask
マスクのアニメーション。鳥のサイズが少し小さくなり、その後大きくなることがわかります。これを 1 つのアニメーションだけで行うには、CAKeyframeAnimation を使用しましょう。
let keyFrameAnimation = CAKeyframeAnimation(keyPath: "bounds")
keyFrameAnimation.duration = 1
keyFrameAnimation.timingFunctions = [CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut), CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)]
let initalBounds = NSValue(CGRect: mask!.bounds)
let secondBounds = NSValue(CGRect: CGRect(x: 0, y: 0, width: 90, height: 90))
let finalBounds = NSValue(CGRect: CGRect(x: 0, y: 0, width: 1500, height: 1500))
keyFrameAnimation.values = [initalBounds, secondBounds, finalBounds]
keyFrameAnimation.keyTimes = [0, 0.3, 1]
self.mask!.addAnimation(keyFrameAnimation, forKey: "bounds")
結果が表示されたら、github リポジトリにアクセスしてください。https://github.com/rounak/TwitterBirdAnimation/
于 2014-09-25T11:30:53.617 に答える