【发布时间】:2016-11-14 07:08:07
【问题描述】:
我做一个 twitter 动画项目作为练习。我想改变遮罩的背景颜色,但不知道为什么要设置窗口背景颜色来改变它。
这是我在 AppDelegate 中的代码
var mask: CALayer?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.mask = CALayer()
self.mask?.contents = UIImage(named: "twitter")?.cgImage
self.mask?.contentsGravity = kCAGravityResizeAspect
self.mask?.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
self.mask?.position = self.window!.center
self.window?.rootViewController?.view.layer.mask = self.mask
self.window?.backgroundColor = UIColor(red: 18/255, green: 145/255, blue: 242/255, alpha: 1) // Why?
return true
}
【问题讨论】:
标签: ios swift window calayer mask