如何以横向显示横向模式?
问题描述:
我有一个Iphone的计算器屏幕,当我启动它以纵向显示时,但我想从纵向显示横向模式的计算器屏幕,也改变方向,怎么样?如何以横向显示横向模式?
我试过的源代码:
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation((M_PI * (90)/180.0));
self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
它用于首次推出只在纵向横向模式,但改变方向不工作,任何一个可以帮助我。
答
试试这个:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[[self view] setBounds:CGRectMake(0, 0, 480, 320)];
[[self view] setCenter:CGPointMake(160, 240)];
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI/2)];
+0
我使用这些代码,它是在纵向模式下启动景观,但改变方向不工作,谢谢 – sankar
答
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES
}
Now make use of any one method for ur rotation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
Hope this help.
答
我的沙盒应用程序: https://github.com/comonitos/programatical_device_orientation
解决办法很简单:
接口(H文件):
BOOL rotated;
实施(M档): 1.改写
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return rotated;
}
2调用[自我设置]
-(void) setup {
rotated = YES;
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft];
rotated = NO;
}
我想你想在这两个方向上运行你的应用程序... ..英寸右..否则请告诉我你确切想要做什么..... –