iOS操场是否支持UIViewanimation?
是否有可能在Playground中预览带有animateWithDuration的UIViewanimation? 我在UIView初始化的时候添加了XCPShowView,它显示了它的最终状态,而不pipe我select的时间轴上的位置。
Xcode 7更新: XCPShowView
已弃用,但可以在操场liveView中看到animation。 还有更多即将推出的互动游乐场
这里是Joseph Chen示例代码的更新。 我也将颜色更改为绿色,因为容器默认背景是黑色的:
import UIKit import XCPlayground let container = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 100.0, height: 100.0)) // XCPShowView("container", view: container) // -> deprecated let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0)) view.backgroundColor = UIColor.greenColor() container.addSubview(view) UIView.animateWithDuration(5) { view.center = CGPoint(x: 75.0, y: 75.0) } XCPlaygroundPage.currentPage.liveView=container
是的,这是(在Xcode 6.1.1上检查,但可能适用于早期版本)。
你应该:
-
select“在完全模拟器中运行”选项(请参阅此答案一步一步)。
-
在容器视图中添加您希望进行animation处理的视图。
例如,这显示了一个黑色方块向左下移动:
import UIKit import XCPlayground let container = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 100.0, height: 100.0)) XCPShowView("container", container) let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0)) view.backgroundColor = UIColor.blackColor() container.addSubview(view) UIView.animateWithDuration(5.0, animations: { () -> Void in view.center = CGPoint(x: 75.0, y: 75.0) })