Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-21-2011, 10:12 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 13
ebarmes is on a distinguished road
Default Rotating a UIView or UIImage without Animation

So far I have...

myClass.h
@interface myClass : UIView {
UIImage* image;
}

-(id)initWithFrame:(CGRect)frame;

@end



myClass.m
- (id)initWithFrame:(CGRect)frame {


UIImage* loadedImage = [UIImage imageNamed:@"aPic.png"];
CGRect rect = CGRectMake(frame.origin.x, frame.origin.y,
loadedImage.size.width,
loadedImage.size.height);


self = [super initWithFrame:rect];
image = [loadedImage retain];

self.opaque = NO;
self.backgroundColor = [UIColor clearColor];


return self;
}


- (void)drawRect:(CGRect)rect{


[image drawInRect:rect];
}


Is there a way to 1) create an instance of myClass then rotate it 45 degrees before adding it to a superview, 2) rotate just the image property 45 before adding to superview, 3) rotate the image property before drawing it in the rect, or 4) rotate the loadedImage before passing it to the image property?
ebarmes is offline   Reply With Quote
Old 02-22-2011, 09:43 AM   #2 (permalink)
Registered Member
 
missing_no's Avatar
 
Join Date: Feb 2011
Posts: 41
missing_no is on a distinguished road
Default

CGAffineTransforms are what you are looking for and this is one of the rare cases where the Cocoa documetation is actually useful:
CGAFFINETRANSFORMS doc

and there is also this great tutorial using Affine transforms:
http://iphonedevelopment.blogspot.co...transform.html


From the documentation:
CGAffineTransform CGAffineTransformRotate (
CGAffineTransform t,
CGFloat angle
);

so say your UIimageView is called "thingy", Make it rotate 90deg

thingy.transform = CGAffineTransformRotate (
thingy.transform,
M_PI/2); // Pi/2 is 90 degrees remember this?

or for scaling:
CGAffineTransform CGAffineTransformScale (
CGAffineTransform t,
CGFloat sx,
CGFloat sy
);

so say your UIimageView is called "thingy", to make it face the oppisite direction (right to left) you would
thingy.transform = CGAffineTransformScale (
thingy.transform,
-1,
1);

they use matrix transformations (hey school really was important) if this doesn't help hit this thread again I'll see what I can do.

Last edited by missing_no; 02-22-2011 at 09:58 AM.
missing_no is offline   Reply With Quote
Old 02-22-2011, 06:14 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 13
ebarmes is on a distinguished road
Default

Thanks bro,
I think my problem was I was trying to use a UIImage which apparently doesnt have a .transform property. So i switched over to a UIImageView instead, now it works like a charm using your "thingy" example, just swapping in my ImageView's name.
ebarmes is offline   Reply With Quote
Old 02-23-2011, 09:55 AM   #4 (permalink)
Registered Member
 
missing_no's Avatar
 
Join Date: Feb 2011
Posts: 41
missing_no is on a distinguished road
Default

Quote:
Originally Posted by ebarmes View Post
Thanks bro,
I think my problem was I was trying to use a UIImage which apparently doesnt have a .transform property. So i switched over to a UIImageView instead, now it works like a charm using your "thingy" example, just swapping in my ImageView's name.
No problem brotato. It's what we are all here for; it's like a neverending "lessons learned" forum.
missing_no is offline   Reply With Quote
Old 03-27-2011, 03:53 AM   #5 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 3
wiegerthefarmer is on a distinguished road
Default

Quote:
Originally Posted by missing_no View Post
No problem brotato. It's what we are all here for; it's like a neverending "lessons learned" forum.
It's been to long since I've been in school to remember the details of matrix transformation! I've found a whole bunch of examples...I'll post them in a sec about making the square image into a parallelogram... but I can't seem to get it working.

Basically I need to make the vertical and horizontal parallel "lines" of the photo further apart or closer together...

Thanks for any help! Getting the links now...

Aaron (wiegerthefarmer)
wiegerthefarmer is offline   Reply With Quote
Old 03-27-2011, 04:02 AM   #6 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 3
wiegerthefarmer is on a distinguished road
Default

here's the links...
iPhone image stretching (skew) - Stack Overflow
iphone - How do I create and apply the image skew transform that I have calculated? - Stack Overflow
iphone - Z direction UIview rotating? - Stack Overflow
tumbljack
I'm heading up to get a coffee...5am...can't sleep... and I'll see if I can piece this together...

Any help or links would be wonderful. The answer is always out there...but not enough hours to google And code magic!!

<edit> Looks like I might have found my solution...
iphone - UIView perspective transform - Stack Overflow

This
Code:
  UIView *myView = self.view;
    CALayer *layer = myView.layer;
    CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = 1.0 / -500;
    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
    layer.transform = rotationAndPerspectiveTransform;

Last edited by wiegerthefarmer; 03-27-2011 at 05:02 AM.
wiegerthefarmer is offline   Reply With Quote
Old 03-28-2011, 09:14 AM   #7 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 2
Ostricide is on a distinguished road
Cool rotating images

Quote:
Originally Posted by wiegerthefarmer View Post
here's the links...
iPhone image stretching (skew) - Stack Overflow
iphone - How do I create and apply the image skew transform that I have calculated? - Stack Overflow
iphone - Z direction UIview rotating? - Stack Overflow
tumbljack
I'm heading up to get a coffee...5am...can't sleep... and I'll see if I can piece this together...

Any help or links would be wonderful. The answer is always out there...but not enough hours to google And code magic!!

<edit> Looks like I might have found my solution...
iphone - UIView perspective transform - Stack Overflow

This
Code:
  UIView *myView = self.view;
    CALayer *layer = myView.layer;
    CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = 1.0 / -500;
    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
    layer.transform = rotationAndPerspectiveTransform;
I have been working on something similar and managed to get an image to rotate in response to the accelerometer. It was not simple or I would just reproduce my steps but I can tell you that you are on the right track.

the end result of all the setup was this little chunk of code.

CATransform3D rotationTransform = CATransform3DIdentity;
rotationTransform = CATransform3DRotate(rotationTransform, bubbleRotation, 0, 0, 1);
bubbleView.layer.transform = rotationTransform;

I think when your trying to change perspective its best to do it seperately. this makes it easier to keep track of the coords.

Hope this is helpful!
Ostricide is offline   Reply With Quote
Reply

Bookmarks

Tags
cgrect, no animation, rotating, uiimage, uiview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 426
8 members and 418 guests
chemistry, ChrisYates, hussain1982, Retouchable, skrew88, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:11 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0