2012-01-31 87 views
1

當我在滾動視圖中查看圖像時,我改變了手機的方向,scrollview不會改變手機的方向。當方向改變時UIScrollview大小

林想知道如果有人可以向我解釋如何做到這一點。

這些都是在我的界面生成器設置

enter image description here

我剛纔已經做了一些研究,現在有第一選擇工作,但如果我嘗試另一張照片它dosnt工作..和我不能確定爲什麼..我的繼承人代碼

這是什麼使這半工作

scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 


- (void)loadImage:(NSString *)myImageName 
{ 
// //Create scrollview 

    scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
    scrollView.delegate = self; 

    //Create scrollviewimage 
    if ([myImageName isEqualToString:@"one"]) { 
     image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hyundai.png"]]; 
     containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 350, 550)]; 
     NSLog(@"1"); 
    } 
    if ([myImageName isEqualToString:@"two"]) { 
     image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"keso.png"]]; 
     containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 600, 520)]; 
     NSLog(@"2"); 
    } 
    if ([myImageName isEqualToString:@"three"]) { 
     image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"conforti.png"]]; 
     containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 600, 700)]; 
     NSLog(@"3"); 
    } 

    //Add subview 
    [containerView addSubview:image]; 
    //initViews 
// scrollView.contentSize = containerView.frame.size; 
    [scrollView addSubview:containerView]; 

    //scrolling 
    scrollView.minimumZoomScale = 1.0; 
    scrollView.maximumZoomScale = 31.0; 
    scrollView.BackgroundColor = UIColor.whiteColor; 
    [scrollView setZoomScale:scrollView.minimumZoomScale]; 

    //highrachy 
    [self.view addSubview:scrollView]; 
    scrollView = nil; 
} 

編輯:應對@D Ĵ

這是輸出

2012-02-01 13:30:35.683 Diagram Test[1672:707] The view controller <UINavigationController: 0x14cdd0> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation. 
2012-02-01 13:30:44.182 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:47.097 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:47.158 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:51.509 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:51.555 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:55.473 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:55.519 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:59.293 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:59.352 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:31:02.237 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:31:02.281 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:31:03.814 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:31:03.858 Diagram Test[1672:707] height = (null)i, width = (null)i 
+0

將圖像添加到UIScrollView的代碼是什麼?其他物體是否改變方向?實際上,在你發佈它之後,就像你有一個UIScrollView佔據整個Iphone屏幕一樣,它可能是你的視圖控制器。 – DJPlayer 2012-02-01 00:22:39

回答

0

這些都是正確的彈簧和支柱具有滾動視圖填補取向變化的父視圖。問題很可能是scrollview內容不適應。

而且看一看修改scrollview.contentSize和scrollView.contentOffest在willRotateToInterfaceOrientation:方法,如果你需要保持圖像居中等

+0

我很確定內容是好的,再次檢查我的問題,因爲我已經用我剛剛發現的其中一張圖片進行了更新。 – 2012-02-01 00:25:29

0

我有一種感覺沒什麼旋轉..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    NSLog(@"height = %i, width = %i",scrollviewname.bounds.size.height, scrollviewname.bounds.size.width); 
    return true; 
} 

我從內存中鍵入該代碼..所以如果有拼寫錯誤對不起..檢查這些日誌,以確保uiscrollview首先旋轉。

+0

我在我的問題中發佈了對此的回覆 – 2012-02-01 00:35:24

2

旋轉scrollview將調整邊界的大小,但不會調整contentSize,它不受autoresize的影響。

contentSize是滾動視圖的可滾動區域,因此您需要在旋轉過程中手動調整它的大小。這可能會導致其他一些調整,所以要警告旋轉scrollview可能有點棘手。

例如,如果您滾動瀏覽圖像列表,您還需要重新對齊滾動位置,並可能需要修改縮放設置以匹配新的寬度和高度。

如果您只放大單張圖像,則該任務會更簡單一些,因爲只有縮放需要進行調整。

另一個提示:使用contentSize播放而不旋轉,這樣您就可以看到它是如何影響滾動和可見區域的。

+0

乾杯..我發現了一些困難的方式..大時間疼痛 – 2012-02-01 00:39:09

相關問題