Swift-Add mobile adsorption behavior to uikit components using UI Dynamics

Source: Internet
Author: User
Tags uikit

UI Dynamics is a new component of Uikit, which provides physics-related features and animations to the views in iOS. Allows you to introduce force and physical properties into the view, allowing your view to bounce, dance, be affected by gravity, and so on.
The following example demonstrates the use of Uisnapbehavior to add a move adsorption behavior to Uiimageview.
as follows: (click on the screen, the Apple will dynamically move to the location of the click, moving with the tilt and easing effect)
1234567891011121314151617181920212223242526272829303132 import UIKitclass ViewController: UIViewController {    @IBOutlet weak var imageView: UIImageView!        var dynamicAnimator = UIDynamicAnimator()    var snap:UISnapBehavior?        override func viewDidLoad() {        super.viewDidLoad()                dynamicAnimator = UIDynamicAnimator(referenceView: self.view)    }        @IBAction func tapped(sender:AnyObject){        //获取点击位置        let tap = sender as! UITapGestureRecognizer        let point = tap.locationInView(self.view)                //删除之前的吸附,添加一个新的        if self.snap != nil {            self.dynamicAnimator.removeBehavior(self.snap!)        }        self.snap = UISnapBehavior(item: self.imageView, snapToPoint: point)        self.dynamicAnimator.addBehavior(self.snap!)    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()    }}

Original from: www.hangge.com reprint please keep the original link: http://www.hangge.com/blog/cache/detail_870.html

Swift-Add mobile adsorption behavior to uikit components using UI Dynamics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.