自动旋转

来源:互联网 发布:最全网络理财投资 编辑:程序博客网 时间:2024/04/28 17:10

自动旋转

自动旋转要注意合适性。
自动旋转的方法:
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(...);

原创粉丝点击