[英]How to display in landscape mode in portrait?
I have a calculator screen in Iphone, when i launched it displayed in portrait,but i want to display the calculator screen in landscape mode from portrait and also change the orientation, how? 我在Iphone中有一个计算器屏幕,当我以纵向显示它时,我想以横向模式显示计算器屏幕,也可以改变方向,如何?
I tried the source code: 我试过源代码:
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation((M_PI * (90) / 180.0));
self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
It is used first time launched only landscape mode in portrait, but change the orientation not working, any one help me. 它是第一次使用纵向仅启动横向模式,但改变方向不起作用,任何一个帮助我。
Try this: 尝试这个:
[[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)];
- (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.
THE same question here 同样的问题在这里
My sandbox app: https://github.com/comonitos/programatical_device_orientation 我的沙箱应用程序: https : //github.com/comonitos/programatical_device_orientation
The solution is easy: 解决方案很简单:
in interface (h file) : 在接口(h文件)中:
BOOL rotated;
in implementation (m file): 1. rewrite 在实现中(m文件):1。重写
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return rotated;
}
2 call [self setup] 2通话[自我设置]
-(void) setup {
rotated = YES;
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft];
rotated = NO;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.