簡體   English   中英

UIImage / UIView不能正確調整為UIInterfaceLandscape視圖

[英]UIImage/UIView Doesn't Adjust Properly To UIInterfaceLandscape Views

我正在編寫一個只希望在橫向模式下查看的應用程序。 我已經對其進行了設置,以便如果iPhone處於縱向模式,則什么也不會發生,並且當前圖像仍保持為橫向模式。 iPhone模擬器以橫向模式啟動,右側為“主頁”按鈕。 如果將iPhone從一種橫向模式旋轉到另一種橫向模式,則會發生動畫並調整視圖。 但是,只要設備處於橫向模式且左側的“主頁”按鈕處於左側,該圖像就會比需要的圖像高20像素,從而在屏幕底部顯示一條白線。

盡管進行了各種邏輯上的調整,例如

self.view.frame = CGRectMake (0,20, self.view.frame.size.width, self.view.frame.size.height)

它不能解決問題。 我在計算中考慮了狀態欄。

.xib文件在UIView頂部包含一個UIImageView 這是我第一次實現這些方法,因此對於該解決方案相對簡單的問題,我深表歉意。 以下是用於實現風景模式視圖的兩種方法的代碼。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    //set up interface to only be viewed in Landscape

    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        return interfaceOrientation;
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return interfaceOrientation;
    else
        return NO;
}

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

    if(UIInterfaceOrientationLandscapeRight){ 
        self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 
    }
    else if (UIInterfaceOrientationLandscapeLeft) { 

         //shouldn't adjustment to 20 fix the view?
        self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }
    else return;
}

對於UIViews適當的調整子視圖,你將不得不看看這個UIView屬性: autoresizingMask ,並設置面罩自動調整所需要的,如果不工作,你將不得不重寫:

- (void)layoutSubviews

來自參考: UIView參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM