Does iOS Playgrounds supports UIView animations?

后端 未结 2 1420
春和景丽
春和景丽 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:29

    Yes, it is (checked on Xcode 6.1.1, but may apply to earlier versions).

    You should:

    1. Select the "Run in Full Simulator" option (see this answer for a step-by-step).

    2. Add the view you wish to animate within a container view.

    For example, this shows a black square moving in a down-left motion:

    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)
    })
    

提交回复
热议问题