Ios 如何在iPad处于纵向模式的情况下强制iPad的电视处于横向模式
我用HDMI电缆将我的iPad屏幕输出到电视上。 如果我将iPad保持在横向模式,电视节目的输出将保持横向模式。如果我将其旋转到电视上的纵向输出,也会切换到纵向模式 有没有办法限制这一点,即即使我将iPad旋转到纵向,电视上的输出也应保持横向 下面是一些图片,可以清楚地说明我的问题 这是我的iPad的定位 这就是我得到的 这就是我想要的 或 我已经从编程的混乱中走了这么远 我在带有iAction方法的Xcode单视图应用程序模板中,在带有一些图像的UIImageView上制作了一个按钮 此方法具有以下代码Ios 如何在iPad处于纵向模式的情况下强制iPad的电视处于横向模式,ios,objective-c,ipad,uialertview,uiscreen,Ios,Objective C,Ipad,Uialertview,Uiscreen,我用HDMI电缆将我的iPad屏幕输出到电视上。 如果我将iPad保持在横向模式,电视节目的输出将保持横向模式。如果我将其旋转到电视上的纵向输出,也会切换到纵向模式 有没有办法限制这一点,即即使我将iPad旋转到纵向,电视上的输出也应保持横向 下面是一些图片,可以清楚地说明我的问题 这是我的iPad的定位 这就是我得到的 这就是我想要的 或 我已经从编程的混乱中走了这么远 我在带有iAction方法的Xcode单视图应用程序模板中,在带有一些图像的UIImageView上制作了一个按钮 此方
- (IBAction)screenButton:(id)sender {
NSLog(@"Screen Count %d",[[UIScreen screens]count]);
if([[UIScreen screens]count] > 1) {
CGSize max;
UIScreenMode *maxScreenMode;
for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
if(current.size.width > max.width)
{
max = current.size;
maxScreenMode = current;
}
}
//UIScreen *external = [[UIScreen screens] objectAtIndex:0];
UIScreen *external = [[UIScreen screens] objectAtIndex:1];
external.currentMode = maxScreenMode;
//external_disp = [externalDisplay alloc];
//external_disp.drawImage = drawViewController.drawImage;
// ExternalDisplayOn = TRUE;
//UIImageView *extView = [[UIImageView alloc] init];
_extView.hidden=FALSE;
_extView.frame = external.bounds;//MyMainScrollView.frame;
UIWindow *newwindow = [[UIWindow alloc] initWithFrame:_extView.frame];
//UIWindow *newwindow = [[UIWindow alloc];
[newwindow addSubview:_extView];
newwindow.screen = external;
newwindow.hidden=NO;
[[[UIAlertView alloc] initWithTitle:@"Alert Showed" message:[NSString stringWithFormat:@"_extView.frame X %f, Y %f, W %f, H %f, Screen Count %d",_extView.frame.origin.x,_extView.frame.origin.y,_extView.frame.size.width,_extView.frame.size.height,[[UIScreen screens]count]] delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil] show];
[newwindow makeKeyAndVisible];
}
}
-(iAction)屏幕按钮:(id)发送者{
NSLog(@“屏幕计数%d”,[[UIScreen screens]计数]);
如果([[UIScreen screens]计数]>1){
cgsizemax;
UIScreenMode*maxScreenMode;
对于(int i=0;i<[[UIScreen screens]objectAtIndex:1]availableModes]count];i++)
{
UIScreenMode*current=[[[UIScreen screens]对象索引:1]可用模板]对象索引:i];
如果(当前大小宽度>最大宽度)
{
最大值=当前尺寸;
maxScreenMode=电流;
}
}
//UIScreen*外部=[[UIScreen screens]对象索引:0];
UIScreen*外部=[[UIScreen screens]对象索引:1];
external.currentMode=maxScreenMode;
//外部显示=[externalDisplay alloc];
//外部_disp.drawImage=drawViewController.drawImage;
//ExternalDisplayOn=TRUE;
//UIImageView*extView=[[UIImageView alloc]init];
_extView.hidden=FALSE;
_extView.frame=external.bounds;//MyMainScrollView.frame;
UIWindow*newwindow=[[UIWindow alloc]initWithFrame:\u extView.frame];
//UIWindow*newwindow=[[UIWindow alloc];
[新建窗口添加子视图:_extView];
newwindow.screen=外部;
newwindow.hidden=否;
[[[UIAlertView alloc]initWithTitle:@“警报显示”消息:[NSString stringWithFormat:@“\u extView.frame X%f,Y%f,W%f,H%f,屏幕计数%d”,\u extView.frame.origin.X,\u extView.frame.size.width,\u extView.frame.size.height,[[UIScreen screens]计数]]代理:无取消按钮:@“确定!”其他按钮:无,无显示];
[newwindow makeKeyAndVisible];
}
}
我在某种程度上能够解决我的问题,但我面临的问题如下
每当我运行应用程序并将其保持在纵向模式时,电视上的输出就是我的iPad屏幕的精确复制品
现在,当我按下上面指定代码的UIButton时,一个UIAlertView会显示在iPad屏幕上(但不会显示在电视屏幕上)。当我的iPad处于纵向模式时,电视上的方向会变成横向(实际上这正是我真正想做的)
但当我按下UIalertView的取消按钮以关闭警报视图时。电视输出上的方向再次更改为纵向模式
当UIAlertView出现时,是否有办法防止我的情况发生。这将解决问题。我不知道我的想法是否有帮助,或者你已经这样设置了程序 在projekt inspector中,你可以强制你的iPad处于某个方向,然后你的应用程序只能在这个方向上运行
它有帮助吗?您应该为您的
新窗口创建一个单独的UIViewController
。rootViewController
可以在其中定义适当的支持方向-您可以尝试在视图上设置90度变换,并将其边界更改为屏幕边界,但大小组件已交换
比如:
CGRect screenBounds = external.bounds;
_extView.transform = CGAffineTransformMakeRotation((CGFloat)M_PI_2);
_extView.bounds = CGRectMake(0,0,screenBounds.size.height, screenBounds.size.width);
您可以使用应用程序委托,根据需要设置应用程序方向
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSLog(@"Interface orientation Portrait = %@",enablePortrait);
if(wantAppliactionTobeLandscape)
return UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
相应地创建bool并根据需要进行设置。您是将同一视图分配给两个窗口,还是同一视图有两个不同的实例?@Dev\u Dash您找到解决方案了吗?