IOS动画效果

在故事版中插入image view绑定一张图片拖入view controller中选择IBOutlet名称为img

先在页面中显示这张图片

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.view.addSubview(img)
    }

触摸后相应图片效果

    override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        //每个效果都需要开始、配置、提交 三步
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromRight, forView: img, cache: true)        //cache是否缓存
        UIView.setAnimationDuration(1.0)//时间
        UIView.commitAnimations()   //提交
    }

你可能感兴趣的:(IOS动画效果)