自动旋转
自动旋转要注意合适性。
自动旋转的方法:
1.自动调整属性。
2.用CGRectMake重新调整位置。
3.用两张视图切换。
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
....;
}
interfaceOrientation 可以是 UIInterfaceOrientationPortrait,
UIInterfaceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight,
UIInterfaceOrientationPortraitUpsideDown.
如果返回YES。则自动旋转。
1.用CGRectMake重新调整位置。
-(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
duration:(NSTimeInterval)duration; //在旋转的后半个动画。
self.interfaceOrientation返回现在的方向。
button.frame属性为CGRect 框架的大小,位置。
动画效果:
[UIView beginAnimation:@"a" context:nil];
.
.
.
[UIView commitAnimation];
2.用两张视图切换。
删除原来视图,新建两个视图。
self.view返回当前的视图。
self.view.bounds返回视图的CGRect
self.view=self.view1; 把view1视图变成当前视图。
Core Graphics框架记得要导入。
CGAffineTransformMakeRotation(弧度).
self.view.transform=CGAffineTransformIdentity;
self.view.transform=CGAffineTransformMakeRotation(...);
本文介绍iOS应用中实现自动旋转的方法,包括使用自动调整属性、利用CGRectMake调整位置以及通过两张视图切换实现平滑过渡。文章还介绍了如何通过shouldAutorotateToInterfaceOrientation方法控制旋转方向,并提供了具体的代码示例。
1万+

被折叠的 条评论
为什么被折叠?



