Does iOS Playgrounds supports UIView animations?

后端 未结 2 1440
春和景丽
春和景丽 2021-02-19 07:46

Is it possible to preview animation done for UIView with animateWithDuration in Playground? I am adding XCPShowView right after initialization of UIView and its shows everything

2条回答
  •  自闭症患者
    2021-02-19 08:28

    Xcode 7 update : XCPShowView is deprecated but you can see the animation in the playground liveView. And there is more coming soon: Interactive Playgrounds

    Here is an update to Joseph Chen sample code. I also changed the color to green as the container default background is black :

    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
    

提交回复
热议问题