Swift-Mobile phone shake monitoring and response

Source: Internet
Author: User

Shaking a mobile phone is also a common means of interaction (such as shaking a shake function). The Shake event has been conveniently fused in the IOS SDK, as simple as triggering a touch event, and the program executes automatically after a shake event occurs.
1234567891011121314151617181920212223 import UIKitclass ViewController: UIViewController {    override func viewDidLoad() {        super.viewDidLoad()    }        //开始摇晃    override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent) {        println("开始摇晃")    }        //摇晃结束    override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent) {        println("摇晃结束")    }        //摇晃被意外终止    override func motionCancelled(motion: UIEventSubtype, withEvent event: UIEvent) {        println("摇晃被意外终止")    }}

Swift-Mobile phone shake monitoring and response

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.