tags:

views:

52

answers:

1

I have a UIView that I wish to alter the size and position of when the view rotates. However, I need to be able to do this programmatically, not using layout settings and autosizing. To this end I have tried changing the frame and bounds of the view when the device rotates and calling for a redraw, but no matter what combination of variables I use the result always comes out wrong. I simply cannot work out what's happening to screw the code up, and there's just too much code to post here. Can someone give me any hints or methods for how this could be accomplished? I just don't know where else to look.

This is the code I use for the portrait layout which works:

clusterMap.frame = CGRectMake(0, self.view.frame.size.height/2, 
        self.view.frame.size.width, 
        self.view.frame.size.height/2);
clusterMap.bounds = CGRectMake(-clusterMap.frame.size.width/2, 
         -clusterMap.frame.size.height/2,
         clusterMap.frame.size.width,
         clusterMap.frame.size.height);
[clusterMap setNeedsDisplay];

But when I try to use an adapted version of this code with different figures, it just displays as if the screen were portrait. If I switch the figures around so that some are portrait and some are landscape, all kinds of weird things happen. One example that I can describe is that the image might draw in the proper proportions, but be clipped to the incorrect proportion's boundary. I've tried every combination of figures I can think of, systematically swapping width and height between paired values one at a time, and none of these combinations work.

+2  A: 

Hello

You need to use the willAnimateRotationToInterfaceOrientation of his controller to achieve this. As you said, you must change his frame property ^^

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}

But if you need more help it could be useful to put some piece of codes ^^

Vinzius
Hm. I'm currently using didRotate from the main application. Would there really be any difference?
Ash
You need a controller to recieve the fact the device orientation change. Or you can try setting a notification but it's not the better way ^^
Vinzius
Sorry, I misread you. What I should have said was I'm using UIDeviceOrientationDidChangeNotification to detect device rotation. The code definitely triggers and sends the data I'm expecting it to send, but somewhere something goes wrong.
Ash
Mmm Can we see your code which change the view layout ? It can be this or it can be the fact your are using this notification instead of the "basic way" I explained in my response.
Vinzius
Just edited the main post.
Ash
Never mind, found the error now. The bounds were being set in a different part of the program that should have been operating on the local transformation matrix instead. The matter was confused somewhat by the way certain values are adjusted by autorotation.
Ash