开发者

Custom UIView rotation issues

开发者 https://www.devze.com 2023-01-17 14:35 出处:网络
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 hav

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.


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 ^^

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号