Problem with simple UIRotationGestureRecognizer

38 views
Skip to first unread message

Zipette

unread,
Jan 25, 2015, 5:58:08 PM1/25/15
to swift-l...@googlegroups.com
Hello,
I want to use the UIRotationGestureRecognizer to rotate an UIView with two fingers on the IOS simulator, here is my Swift code in ViexController:


import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var myView: UIImageView!

    override func viewDidLoad() {

        super.viewDidLoad()

        let gestureRec = UIRotationGestureRecognizer()

        gestureRec.addTarget(myView, action: "rotate:")

        myView.addGestureRecognizer(gestureRec)

        myView.userInteractionEnabled = true

        myView.multipleTouchEnabled = true

    }

    func rotate(sender:UIRotationGestureRecognizer)

    {

        myView.transform=CGAffineTransformRotate(myView.transform, sender.rotation)

        sender.rotation=0

        println("ok !")

    }


Unfortunatly this code doesn't work for a raison I can't find, could someone help me ?

Thks in advance.
Zipette



Sam Stigler

unread,
Jan 25, 2015, 6:23:33 PM1/25/15
to Zipette, swift-l...@googlegroups.com
It looks like you're not using the designated initializer for that class. Have you tried with that to see if it makes a difference?

Sam

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swift-languag...@googlegroups.com.
To post to this group, send email to swift-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/06c9ecea-ec81-447d-b4a1-e1ad67bccdbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zipette

unread,
Jan 26, 2015, 5:16:26 AM1/26/15
to swift-l...@googlegroups.com, conta...@votrecalendrier.com
Hello SAm,
Thks for your answer. How do I invoke the designated initializer for this class ?
Thks.

Sam Stigler

unread,
Jan 26, 2015, 9:43:28 AM1/26/15
to Zipette, swift-l...@googlegroups.com
Hi Zipette,

Check in the documentation for the superclass. In this case, the superclass is UIGestureRecognizer, and its designated initializer is init(target targetAnyObject,
     action actionSelector) . It should show up in Xcode's autocomplete menu if you type in UIRotationGestureRecognizer( .

Sam
Reply all
Reply to author
Forward
0 new messages