本文介绍了强制设置横向在 xib 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码
#define degreesToRadian(x) (M_PI * (x) / 180.0)
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
self.view.bounds = CGRectMake(0.0f, 0.0f, 1004, 768.0f);
// self.view.center = CGPointMake(160.0f, 240.0f);
[UIView commitAnimations];
}
此代码适用于强制设置横向
This code will work fine for force setting landscape orientation
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
我在 viewdidload 中使用以下代码.此代码在测试应用程序中运行良好,但在我的主应用程序中运行良好.
I am using the following code in viewdidload.This code is working fine in test app but in my mainapp.
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
{
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:),UIInterfaceOrientationLandscapeLeft);
}
}
如果我编写测试应用程序就可以正常工作但是在我的 Mainapp 中它不起作用.我的 Mainapp 中有 xib
It is working fine if i write test applicationBut in my Mainapp it is not working.I have xib in my Mainapp
推荐答案
确保您已为 Mainapp 应用程序设置横向模式,
Make sure You have set Landscape mode for your Mainapp Application,
编辑
在 Printview 页面 ios5 和 6 中使用以下方法
Than use Following method in Printview page ios5 and 6
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsLandscape( interfaceOrientation)) {
return YES;
}
return NO;
}
iOS 7
-(BOOL)shouldAutorotate
{
if (UIInterfaceOrientationIsLandscape( [[UIDevice currentDevice] orientation])) {
return YES;
}
else
return NO;
}
这篇关于强制设置横向在 xib 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!