gpt4 book ai didi

iphone - 改变 iPad 方向时 Xcode 4.5 的问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:31:47 26 4
gpt4 key购买 nike

自从我升级到 XCODE 4.5 后,我就面临这个问题。

我有各种 UI 元素

UIButton *button1;
UIButton *按钮2;
UIButton *button3;

- (void)viewDidLoad
{
button1 =[[UIButton alloc]init ];
button1.backgroundColor=[UIColor yellowColor];
[self.view addSubview:button1];


button2 =[[UIButton alloc]init ];
button2.backgroundColor=[UIColor yellowColor];
[self.view addSubview:button2];


button3 =[[UIButton alloc]init ];
button3.backgroundColor=[UIColor yellowColor];
[self.view addSubview:button3];
}

其框架在

中声明
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation==UIInterfaceOrientationPortrait ||[interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown )
{


button1.frame=CGRectMake(10,10,10,10);
button2.frame=CGRectMake(10,30,10,10);

button3.frame=CGRectMake(10,50,10,10);
}
if(interfaceOrientation ==UIInterfaceOrientationLandscapeLeft ||interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
button1.frame=CGRectMake(20,10,10,10);
button2.frame=CGRectMake(20,30,10,10);

button3.frame=CGRectMake(20,50,10,10);
}

return YES;

}

但是框架没有在 Xcode 4.5 中设置..在以前的版本中它运行良好。

我的应用程序非常需要自动调整大小。所以帮助我。

最佳答案

您应该需要在 viewController 中实现新方法(在“ios 6”中引入)以实现方向

- (BOOL)shouldAutorotate
{

return TRUE;

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;


}

修改你的代码将你的代码放在下面的方法中

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)  interfaceOrientation duration:(NSTimeInterval)duration
{

}

同时检查你的窗口,你需要在窗口上添加 Controller 作为 rootviewController 而不是像下面这样的 addSubview

self.window.rootViewController=viewController;

关于iphone - 改变 iPad 方向时 Xcode 4.5 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12582366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com