Rotate a UIImageView with a touch gesture - iphone dev - iphone

Been having real trouble with this one and wondered if someone may have found a solution to this issue.
I would like to be able to rotate a UIImageView using a touch gesture
-> So when the user places two fingers on the touch area and rotates their fingers the UIImageView will rotate with them (Rotating in whatever direction the user moves their fingers)
I can do this but with one issue.... as the UIImageView rotates it does not keep its shape. It seems to skew?? It is really strange and i can not understand why it is happening.
So if i start with an equal sided square... as i rotate it does not remain as an equal sided square the sides seem to skew and not remain equal.
SOOOO i was wondering if anyone has come across this issue, or if anyone has successfully rotated a UIImageView with a touch gesture without it skewing.
Any help regarding this issue is highly appreciated.
Cheers
Tom

Can you give us some more information, like the rotation code?
Hopefully you're doing something like the following:
[imageView setTransform: CGAffineTransformMakeRotation(M_PI/2)];

Related

How to set more directions for UISwipeGestureRecognizer?

UISwipeGestureRecognizer has four directions that I can set: up, down, right, left.
but as I tried to set, the direction of a swipe seems need to be quite precise. I mean, for example, if I set a UISwipeGestureRecognizer with toUp direction, and if I swipe my finger not that precise toUp, say 45 degree in the middle of up and right, the UISwipeGestureRecognizer can't get it.
But I noticed that for UIScrollView, it is not the case.
So How can I give more directions for UISwipeGestureRecognizer or how can I make the direction check more relax?
Thanks
It's probably best to use Apple's swipe gesture to be consistent with their Apps. You could try defining your own by subclassing the UISwipeGestureRecognizer, or creating your own class using the older UITouchesBegan, UITouchesEnded, etc methods.

Cocoa Touch - Floating Image bouncing across screen

I need help with making a UIImageView float on the screen and when it hits the walls it bounces off like collision detection..
I havent gotten further than making the imageview. I need some help..
Any help? Thanks!
What is the best way to make a bouncing ball animation with infinite loop on iPhone?

Cocos2D, UIScrollView, and initial placement of a scene

I am using a UIScrollView to forward touches to Cocos2D as outlined in http://getsetgames.com/2009/08/21/cocos2d-and-uiscrollview/
Everything works great after a few days of working with it, except one thing: when the initial view appears on the screen, the background appears to be scrolled to the center. As soon as I try to scroll around, the image jumps to 0,0, and everything works as normal, except the touches are offset by half the width and height of the background image. Am I overlooking something basic? I can't think of a useful portion of the code that illustrates the issue, as I can't track it down, but would be happy to post code if anyone has any ideas.
Thanks in advance,
-Roberto
I just had to localize the touches in respect to the window, by using nil in locationInView. This returns the touch's location on what's currently visible in the display.
CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:nil]];

How much a UIImageView rotated?

I have an UIImageView that is being pinched, zoomed, rotated, etc. When the user ends transforming the image he presses the DONE button and I have to figure out how much the object was scaled and rotated.
All I know is the angle and scale of the object before the user started modifying it. Now I need the new angle and scale.
How to do that? If you can point to a code, it will help.
thanks
I suggest to keep a track of all changes made.
If the user pinches zooms,etc, it means that the app will calculate the rotation and zooming for every touch the user does right?
So, Why don't use the last touch to know the rotation and zoom?
You could update your zoom and rotation variable every time the user does a touch.
Regards
Ignacio

Flipping UIViews From Top / Bottom

I'm well aware that there are only two available UIView transitions, UIViewAnimationTransitionFlipFromLeft and UIViewAnimationTransitionFlipFromRight. I'm wondering if there is anyway that I can implement / emulate a UIViewAnimationTransitionFlipFromTop or UIViewAnimationTransitionFlipFromBottom.
The only way I can think to do this is by flipping the x axis with the y axis, but I've not seen any information about how to do this. Just setting the coordinates of each axis won't fix the issue as the x-axis till remains the x-axis.
Does anyone have any ideas how this can be accomplished?
You can do this by applying a CATransform3D to your main view's CALayer, with your secondary view's CALayer behind it. In this response, I point to a Mac implementation of this animation by Mike Lee. You should be able to reuse a significant portion of that code to recreate this effect on the iPhone.
Guess you'll have to use a UIView animation block with a 3D rotation transform of 90 degrees, have the Core Animation delegate call you when that's done, swap the view with the new one (3D rotated on the other side) and chain with the last 90 degrees for the new view...
Although its not exactly what you want, there are two built-in animations that you didn't mention: UIViewAnimationTransitionCurlDown and UIViewAnimationTransitionCurlUp.
CurlUp looks like someone is peeling the view from the bottom up to the top, and CurlDown looks like the view is being unrolled down on top of the screen from top to bottom. You should at least give them a look, as they are easy to use.