关于CALayer的两个问题
- 使用
[myLayer setName:@"layer_1"]
设置图层的名称。但我怎样才能从另一种方法得到它呢?是否有类似[self.view.layer.sublayers getLayerByName:@"layer_1"]
的内容? - 如何为
CALayer
设置动画以将其移动到另一个位置并具有良好的平滑效果?
- with
[myLayer setName:@"layer_1"]
I set the name of a layer. But how can I get it from another method? Is there something like[self.view.layer.sublayers getLayerByName:@"layer_1"]
? - how to animate a
CALayer
to move it to another position with a nice smooth effect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
name
属性主要供某些布局管理器使用,但 iOS 上不存在布局管理器,因此此时它真正有用的就是调试。至于动画,如果您使用自己创建的 CALayer,则在更改属性时将获得隐式动画。您可以使用 CAAnimation 子类,您还可以使用 CATransaction。
如果您使用与
UIView
关联的图层,则所有隐式动画都会被禁用。您仍然可以使用CAAnimation
子类创建显式动画,也可以使用 UIView 动画方法。The
name
property is primarily intended for use by some layout managers, except layout managers don't exist on iOS, so all it's really useful for at this point is debugging.As for animation, if you're using a CALayer you created yourself, you'll get implicit animations when you change properties. You can set explicit animations using the CAAnimation subclasses, and you can also tweak some parameters of the implicit ones with CATransaction.
If you're using a layer that's associated with a
UIView
, all implicit animations are disabled. You can still create explicit ones with theCAAnimation
subclasses, or you can use the UIView animation methods.