Background: I wanted to animate the change in my content along with the orientation. My content position is relative to the self.view.bounds
.
Problem: In order to animate the content along with the bounds, I would need to know what would the bounds of the view be at the end. I can hard code it but I hope to find a more dynamic way.
Codes: So all animation takes place in willRotateToInterfaceOrientation
as per following:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//centering the image
imageView.frame = CGRectMake(self.view.bounds.origin.x + (self.view.bounds.size.width - image.size.width)/2 , self.view.bounds.origin.y + (self.view.bounds.size.height - image.size.height)/2, image.size.width, image.size.height);
NSLog(@"%d",[[UIDevice currentDevice] orientation]);
NSLog(@"%f", self.view.bounds.origin.x);
NSLog(@"%f", self.view.bounds.origin.y);
NSLog(@"%f", self.view.bounds.size.width);
NSLog(@"%f", self.view.bounds.size.height);
}
The bounds are before the orientation change. Thus, this only works if the transformation is 180 degrees. If I were to use didRotateFromInterfaceOrientation
, the animation will be after the orientation change which looks awful.