i have UISwipeGestureRecognizer that detects if the user has swiped. i also draw the users touches using the touches moved method found in the tutorial below.
http://www.ifans.com/forums/showthread.php?t=132024
My issue is the gesture seems to override my drawing. is it possible to do both or is there a better way of doing this?
Thanks
Dan
All of the touches methods get overridden when you invoke a gestureRecognizer. You can view it here in the explanation. It may be best to just write your own code to recognize a gesture if you need all of the touch events for drawing updates. If you still want to use a gestureRecognizer, you can use the locationInView: method to find the location of the touch, and then pass those points to your draw method.
I would also think about using OpenglES instead, as it isa bit easier, and you can do more things. There's a great sample project about it here. Hope that helps!
I'm trying to build a testing script for my iPhone application. Inside this test, I'm trying to simulate a pinch action.
I read on the official Apple reference that is possible to call the pinchOpenFromToForDuration function of UIATarget, but the simulator responds to this action how a double tap action (I'm sure because with double tap i perform another action in my code).
I can't understand how I can solve this problem, is possible to use any other trick to reach the same result?
Thank's
Marco
The odd behavior you are experiencing very well could be the coordinates you are using for the pinchOpenFromTo operation.
If the coordinates translate to something that does not "pinch" - like a WebView - then you usually get the click or tap result you mention. That has been my experience, anyway.
Use UIGestureRecognizer class for the zooming functionality. It would be easy for you to handle.
If you are in need of Pinch gesture use UIPinchGestureRecognizer class and delegate to handle that.
For Tap you may use UITapGestureRecognizer class and delegate methods….
I want to make an app like "10,500 cool facts"
Basically, there is some text on background, and then the user will shake, or slide right/left to navigate between the different facts.
I am new to iPhone programming/SDK, so wondering if anyone could help me get started.
How do I implement a shake / slide function?
First, I urge caution when wanting to use a shake gesture for anything, especially if you are new to iOS programming. It was all the rage when the first apps started coming out, until people started realizing that shaking was being used for just about anything, making it mostly a meaningless feature. It's become, for the lack of a better term, passe.
If you're committed to the shake gesture, you'll want to subclass UIWindow and implement the following methods:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent*)event;
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent*)event;
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent*)event;
The UIEventSubtype you're looking for is UIEventSubtypeMotionShake.
As for your "slide" function, I assume you're basically talking about paging between screens horizontally. There are a number of ways you can do this, and I think it will boil down to how you're implementing your underlying view controller hierarchy. I haven't done it myself, but if I were, I'd probably just manually detect user touches on my view to determine if someone's swiping left-to-right or right-to-left, and then change views with a matching transition animation.
Can i create custom touch events for iPhone?? will the device support for creating my own touch event handling ?
Take a look at the UIResponder class:
http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html
You will probably want to implement the touchesBegan:withEvent:, touchesEnded:withEvent: and touchesCancelled:withEvent: methods. These will all be called with an NSSet of UITouches that you can do whatever you want with.
As of the 3.2 SDK there are UIGestureRecognizer classess. They do not play well with the older UIResponder calls, but if you can do 3.2 only they are easier to get going.
There are a number of handy subclasses, such as UIRotationGestureRecognizer for handling rotation.
If you are extending Apple classes like UIScrollView you must use gesture recognizers with 3.2 and later because when a gesture recognizer cancels it will cancel your UIResponder call tracking as well. If you are handling all the gesture tracking this is not an issue.
What are single-state and two-stage animation for rotating an iPhone window?
This is the "error" message I get in the Debugger Console (nothing crashes):
Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
I was working through the book "Beginning iPhone Development: Exploring the iPhone SDK" by Apress (Dave Mark, Jeff LaMarche) on the Swap Project.
Everything is explained in the UIViewController Class Reference. Especially check out the View Rotation section near the top.
From the reference:
Handling View Rotations
By default, the UIViewController class
displays views in portrait mode only.
To support additional orientations,
you must override the
shouldAutorotateToInterfaceOrientation:
method and return YES for any
orientations your subclass supports.
If the autoresizing properties of your
views are configured correctly, that
may be all you have to do. However,
the UIViewController class provides
additional hooks for you to implement
additional behaviors as needed.
To temporarily turn off features that
are not needed or might otherwise
cause problems during the orientation
change, you can override the
willRotateToInterfaceOrientation:duration:
method and perform the needed actions
there. You can then override the
didRotateFromInterfaceOrientation:
method and use it to reenable those
features once the orientation change
is complete.
If you want to perform custom
animations during an orientation
change, you can do so in one of two
ways. Orientation changes used to
occur in two steps, with notifications
occurring at the beginning, middle,
and end points of the rotation.
However, in iPhone OS 3.0, support was
added for performing orientation
changes in one step. Using a one-step
orientation change tends to be faster
than the older two-step process and is
generally recommended for any new
code.
To add animations for a one-step
orientation change, override the
willAnimateRotationToInterfaceOrientation:duration:
method and perform your animations
there. To use the older two-step
method, override one or both of the
willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
and
willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
methods to configure your animations
before each step. You must choose only
one technique and override just the
methods associated with that
technique. If you override either
method associated with the two-step
technique, the view controller uses
that technique by default.
I have found the culprit in my case to be the UIImagePickerController (I also do not override any rotation animation):
[self presentModalViewController:imagePicker animated:YES];
Replacing imagePicker with a generic UIViewController doesn't generate any warnings.
I changed from willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: method to willAnimateRotationToInterfaceOrientation:duration: method and warning gone.
Thanks.
Ed Marty's answer is the correct one. The reason it will happen if you are not overriding any of the rotation animation is probably that you reply "YES" to shouldAutorotate.. for some view. If you do not implement rotation at all, then you should just not override the shouldAutorotate.. method. If you do override that method, then just override the single step rotation method as well and pass it along to the super.
If you're using iOS 4 and you're getting this warning, I found a way to get rid of it. In your info.plist, there is an item called "Supported interface orientations." Select which orientations your application supports and two-stage warnings will go away when bringing up the imagePicker.
#plumiscles answer didn't quite work for me - there was no item called 'Supported Interface Orientations', probably b/c it is an old project. But you can get the same effect by editing the .plist file directly and adding this:
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationPortrait</string>
Need to add UIImagePickerController as a subview to solve this error
[self.view addSubview:picker.view];
[self presentModalViewController:picker animated:NO];
I've had this issue after creating a tabbarcontroller with no view controllers inside (no tabs), this warning disappeared once I attached at least one view controller to it.
I wasn't over riding any of those two-step functions, but I was calling my own function when I received orientationChanged notifications, and I had this line of code in it. Commenting it out got rid of the warning and allowed the auto rotate to work properly. Auto rotate still worked with this line of code until iOS 4.2, then it broke completely. Spent a lot of time looking for why the built in autoRotate stopped working in 4.2. Maybe this will help someone else.
Commented out this line to make it work:
[[UIApplication sharedApplication] setStatusBarOrientation:currentOrientation animated:YES];
I've delete from plist "Supported interface orientations" row and warning disappears.
I just had the same problem. In my case was a silly mistake that I'm putting here just in case anyone else falls into that same issue.
In my tabbed app I remove one of the original ViewControllers and added a new one with Storyboard to create a "Settings" section.
This new VC had to be a table view VC and even I designed, compiled and run it without a problem, when I changed the orientation of the app I kept getting this “Using two-stage rotation animation” error.
My problem was that I forgot to change in the original .h file interface "UIViewController" for "UITableViewController".
Once this was done I changed on the Storyboard identity badge the class from the general value to my SettingsViewController and that was the end of it.
I hope it can help someone else. It took me a while to get to bottom of this.
Cheers,