是否可以在 Playground 中使用 animateWithDuration 预览为 UIView 完成的动画?我在 UIView 初始化后立即添加 XCPShowView ,无论我选择时间轴上的哪个位置,它都会以最终状态显示所有内容。
问问题
4118 次
2 回答
6
是的(在 Xcode 6.1.1 上检查过,但可能适用于早期版本)。
你应该:
选择“在完整模拟器中运行”选项(请参阅此答案以了解分步)。
在容器视图中添加您希望设置动画的视图。
例如,这显示了一个黑色方块在左下运动:
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)
})
于 2015-01-25T10:17:17.493 回答
3
Xcode 7 更新:XCPShowView
已弃用,但您可以在 Playground liveView 中看到动画。还有更多即将推出:交互式游乐场
这是 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
于 2016-03-18T13:53:42.890 回答