iOS:定位获得未来的self.view.bounds

Byt*_*yte 4 objective-c rotation orientation bounds ios

背景:我想为我的内容的变化和方向设置动画.我的内容是相对于self.view.bounds.

问题:为了使内容与边界一起动画化,我需要知道视图的边界到底是什么.我可以硬编码但我希望找到一种更有活力的方式.

代码:所以所有动画都willRotateToInterfaceOrientation按照以下方式进行:

- (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);

}
Run Code Online (Sandbox Code Playgroud)

边界方向改变之前.因此,这仅在转换为180度时才有效.如果我要使用didRotateFromInterfaceOrientation,动画将方向改变看起来很糟糕.

Mis*_*Moo 11

willAnimateRotationToInterfaceOrientation:duration:改用.从旋转动画块中调用此方法,此时已正确设置了所有边界.文档.