Two-Finger View Flip in Official SDK?

Discussion in 'iOS Development' started by cocotutch, Jan 15, 2009.

  1. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    I really need to be able to Rotate my UIImageView with this piece of code.

    Code:
    UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
    UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
    CGPoint previousPoint1 = [touch1 previousLocationInView:nil];
    CGPoint previousPoint2 = [touch2 previousLocationInView:nil];
    CGFloat previousAngle = atan2 (previousPoint2.y - previousPoint1.y, previousPoint2.x - previousPoint1.x);
    				
    CGPoint currentPoint1 = [touch1 locationInView:nil];
    CGPoint currentPoint2 = [touch2 locationInView:nil];
    CGFloat currentAngle = atan2 (currentPoint2.y - currentPoint1.y, currentPoint2.x - currentPoint1.x);
    				
    CGAffineTransform transform = CGAffineTransformRotate(transform, currentAngle - previousAngle);
    Tview.transform = transform;
    But, I open up the Simulator, and I have the code to detect if it is a "One Finger" or "Two Finger". One Finger does absolutely nothing like I want it to.

    However, when I tap with Two Fingers the view I want to rotate with my two fingers just vanishes. I tap the button I have included in my Nest Menu (Don't ask

    Please Register or Log in to view images

    ) and the view seems to stretch back to normal and rotate on the Z axis right back to me.

    For an example of what effect I want, look at MultiTouchDemo from Stanford's iPhone Dev Lectures page. I don't have the link. Tap the middle image with two fingers and rotate them, it scales and flips, The code above, is to simply flip with no zoom.

    This is driving me insane

    Please Register or Log in to view images



    Any help would be VERY appreciated,


    EDIT:

    SkylarEC has assisted me with this problem. Thanks to him, I have solved this issue. As promised in his Thread (in Tutorials SDK) I am posting a screenshot (or two) of how I used the code.


    Picture 1.png


    Picture 2.png


    **My School timetable is listed above in my application, it is sort of a "Multi-Touch enabled PDA" within an iPhone.

    Please Register or Log in to view images

    Please Register or Log in to view images

    Please Register or Log in to view images



    Thankyou again,

    cocotutch
  2. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    take a look at this, from CoreGraphics:

    Code:
    CG_EXTERN CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle);
  4. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    I don't really know what to look at. I have looked in the Docs, and actually have used a command like that to do a separate Button-triggered degreesToRadians rotate. I just don't know how to make it progress with the position of my fingers?

    Any more help?

    P.S. That code has errors/warnings in it, saying "atan2" may not respond or something. Do I need to import something to make it work? I.E. #import "mathsfunctionsheader.h"?
  5. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    include math.h. Also, you need to do some math. No one is going to do it for you.
  6. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    I have the code I need for it to work, it just needs correction...I have tried everything, It just makes my UIImageView vanish on a double tap. My friend gave it to me, it works for him, Multiple Touch is enabled on the layer in IB.

    se nerdenfor post.

    I have hit a road block here,

    cocotutch
  7. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Post your code, and we'll see what we can do.
  8. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Code:
    UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
    UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
    CGPoint previousPoint1 = [touch1 previousLocationInView:nil];
    CGPoint previousPoint2 = [touch2 previousLocationInView:nil];
    CGFloat previousAngle = atan2 (previousPoint2.y - previousPoint1.y, previousPoint2.x - previousPoint1.x);
    				
    CGPoint currentPoint1 = [touch1 locationInView:nil];
    CGPoint currentPoint2 = [touch2 locationInView:nil];
    CGFloat currentAngle = atan2 (currentPoint2.y - currentPoint1.y, currentPoint2.x - currentPoint1.x);
    				
    CGAffineTransform transform = CGAffineTransformRotate(transform, currentAngle - previousAngle);
    Tview.transform = transform;
    Thats the code that has stumped me. Like I said, it "sort of" works, by making the UIImageView (Tview) vanish on a double-fingered tap. The effect is to rotate with two fingers, but not have it "zoom".

    Thank-you again,

    cocotutch

    Edit 1:
    Code:
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {	
    
    	
    
    	
    	UITouch *touch1 = [[touches allObjects] objectAtIndex:0];
    	UITouch *touch2 = [[touches allObjects] objectAtIndex:1];
    	CGPoint previousPoint1 = [touch1 previousLocationInView:nil];
    	CGPoint previousPoint2 = [touch2 previousLocationInView:nil];
    	CGFloat previousAngle = atan2 (previousPoint2.y - previousPoint1.y, previousPoint2.x - previousPoint1.x);
    	
    	CGPoint currentPoint1 = [touch1 locationInView:nil];
    	CGPoint currentPoint2 = [touch2 locationInView:nil];
    	CGFloat currentAngle = atan2 (currentPoint2.y - currentPoint1.y, currentPoint2.x - currentPoint1.x);
    	
    	
    	CGAffineTransform transform = CGAffineTransformRotate(transform, currentAngle - previousAngle);
    	Tview.transform = transform;
    	
    	
    }
    
  9. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    You have it commented out... Did you know? :S
  10. 101gfx

    101gfx New Member

    Joined:
    Jun 6, 2008
    Messages:
    349
    Likes Received:
    0
    Device:
    iPod touch
    rofl. that might be a reason why.

Share This Page