2013-03-05 100 views
0

我知道有一些關於UIImageView全尺寸的問題已經被問到,但我仍然堅持我的問​​題。全屏顯示UIImageView(320 * 480)

我有一個導航欄,滾動視圖,UIImageView(名爲avatarTest)和一個按鈕。當我按下圖像時,UIImageView展開爲全尺寸(320 * 480),並將avatarTest.contentMode設置爲ModeCenter。

我的問題是:

  • 的UIImageView擴大到320 * 480,但它並不能代替導航欄和狀態欄(如圖片1和2)

  • 當我向下滾動(現在我的按鈕出現了),然後按下圖像,UIImageView仍舊按照舊視圖展開。我希望它擴大到全尺寸,填充我當前的視圖(窗口)(如圖3和4)

  • 我想知道如何通過代碼確定UIImageView的原始幀(CGRectMake),以便我可以編碼第二按壓動作(圖片大小調整爲原點)

enter image description here

enter image description here

enter image description here

enter image description here

下面是我的一些viewController.m代碼:

- (IBAction) expand { 

    [UIView animateWithDuration:0.5f animations:^{ 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
     CGFloat screenWidth = screenRect.size.width; 
     CGFloat screenHeight = screenRect.size.height;    
     avatarTest.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, screenWidth, screenHeight); 
     avatarTest.contentMode=UIViewContentModeCenter; 
     avatarTest.backgroundColor = [UIColor blackColor]; 


    }]; 
} 
+0

你的問題沒有意義。圖片3或4如何全尺寸?什麼是「舊觀點」? – Mundi 2013-03-05 17:13:27

回答

3

首先,你必須確保你的框架是正確的。我注意到你保留了原點的x和y,也許這些都必須每次都重置。一些實驗很快會導致期望的結果。

第二個,通過將contentMode設置爲UIViewContentModeCenter您正在防止圖像縮放。您需要啓用縮放圖像像其中的一個內容模式:

UIViewContentModeScaleToFill 
UIViewContentModeScaleAspectFit 
UIViewContentModeScaleAspectFill 

最後,涵蓋了導航欄,你將不得不從主視圖中刪除視圖和添加它代替窗口

[avatarTest removeFromSuperview]; 
[self.view.window addSubview:avatarTest]; 

當然,重置您將不得不做相反的事情。
另外,我建議在viewDidDisappear中清除它。

+0

非常感謝。我成功地做到了。但我仍然不知道如何確定我的原始幀的x,y,寬度和高度,以便從頭開始恢復。其實我必須檢查故事板中的x,y ...才能知道。先謝謝你。對不起,我的英語不好。 – jackiviet 2013-03-06 09:24:08

2

要擺脫狀態欄和導航欄,你必須隱藏它們。隱藏他們沒有動畫...

[self.navigationController setNavigationBarHidden:YES animated:NO]; 
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; 

當然,當你想要他們回來你必須設置隱藏到NO。

+0

非常感謝。它的作用像一個魅力:D – jackiviet 2013-03-06 09:27:17