[英]How to manage portrait and landscape orientation of iPad in Xcode?
我正在制作 iPad 應用程序
我只在肖像中設置了所有內容的框架
但我也想要風景的方向
在 appTarget 中,我選擇了所有支持的界面方向。
在縱向模式下它運行良好但是當我在橫向模式下移動它時
然后我的視圖和我的所有控件都亂了,看起來很糟糕
你能告訴我如何管理所有的方向嗎
請告訴我一些簡單的細節
將此添加到您的 AppDelegate.m 文件以支持兩種方向。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}
試試這個..... 假設你的 ipad 底角有一個按鈕。 那么如何在橫向和縱向模式下將它放在同一位置......
-(NSUInteger)supportedInterfaceOrientations
{
if ([[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationMaskPortrait||[[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationMaskPortraitUpsideDown) {
pButton.frame=CGRectMake(self.view.frame.size.width-70, self.view.frame.size.height-70, 70, 70);
}
else
{
pButton.frame=CGRectMake(self.view.frame.size.width-70, self.view.frame.size.height-70, 70, 70);
}
return (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight|UIInterfaceOrientationMaskPortraitUpsideDown);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if ([[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationMaskPortrait||[[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationMaskPortraitUpsideDown) {
pButton.frame=CGRectMake(self.view.frame.size.width-70, self.view.frame.size.height-70, 70, 70);
}
else
{
pButton.frame=CGRectMake(self.view.frame.size.width-70, self.view.frame.size.height-70, 70, 70);
}
return YES;
}
看到您必須覆蓋這些方法以在兩種模式下調整您的 gui,並且您必須在這些方法中調整您的 GUI 元素的框架。 . .
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.