4

後滾動或交互作用。在我的UIScrollView不會讓旋轉

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 

方法,我有一些代碼來重新定位和應用程序與設備旋轉調整滾動型。我用下面的代碼:

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:0.5f]; 

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     //landscape 
    [mT.buttonScroll setFrame:CGRectMake(0, 544, 1024, 160)]; 

    }else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){ 
     //landscape 
    [mT.buttonScroll setFrame:CGRectMake(0, 544, 1024, 160)]; 

    }else if (toInterfaceOrientation == UIInterfaceOrientationPortrait){ 
     //portrait 
    [mT.buttonScroll setFrame:CGRectMake(0, 800, 768, 160)]; 

    }else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){ 
     //portrait 
    [mT.buttonScroll setFrame:CGRectMake(0, 800, 768, 160)]; 

    } 
} 

一切正常旋轉,但一旦我第二次旋轉滾動視圖變得完全不可觸摸。無法滾動或觸摸其中的任何按鈕。然後,如果我旋轉回到先前的視圖,觸摸回來等等。有誰知道它爲什麼這樣做?

+0

你是否更新滾動視圖的內容大小? –

回答

0

我認爲你應該使用shouldAutorotateToInterfaceOrientation並觀察你的旋轉和UI響應。

在我的測試中,它與我提到的方法正常工作。 willRotatetoInterfaceOrientation在其「應該」對應之後被調用。否則,它根本不會被調用。

-1

檢出滾動視圖的框架。旋轉後,滾動視圖的框架穿過窗口框架,因此滾動視圖不響應觸摸。

而且我假設而計算你都考慮到RECT其它視圖RECT如果存在像導航欄,TabBar,所以狀態欄

4

改變Frame是一切都很好,但是當涉及到UIScrollViewscontentSize這使所有的差異。更改方向時需要設置contentSize。在改變方向時,你可以通過添加這樣的東西來做到這一點。

[mT.buttonScroll setContentSize:CGSizeMake(width, height)]; 

我認爲mT.buttonScroll是某種UIScrollView

這裏發生了什麼是你重置內容區域的大小基本上你想要的大小。你可以在這裏修改寬度和高度。

希望這有助於如果不給我們留言,我會盡力幫助。

0

除了大力水手的答案(這是正確的;)我發現我需要設置內容的大小這樣的地方,以避免這個問題。

-(void)viewDidAppear:(BOOL)animated{ 
[super viewDidAppear:animated]; 
[scroller setScrollEnabled:YES]; 
[scroller setContentSize:CGSizeMake (0,100)]; 
} 

-(void)viewWillAppear:(BOOL)animated{ 
[super viewWillAppear:animated]; 
[scroller setScrollEnabled:YES]; 
[scroller setContentSize:CGSizeMake (0,100) ]; 
} 

-(void)viewDidLoad 
{ 
[super viewDidLoad]; 
[scroller setScrollEnabled:YES]; 
[scroller setContentSize:CGSizeMake (0,100) ]; 
} 

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) 
{ 
NSLog(@"Lanscapse"); 
[scroller setScrollEnabled:YES]; 
[scroller setContentSize:CGSizeMake (0,100]; 
} 
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) 
{ 
NSLog(@"Portrait"); 
[scroller setScrollEnabled:YES]; 
[scroller setContentSize:CGSizeMake (0,100) ]; 
} 
} 
0

我也面臨着同樣的問題 遵循以下步驟: 確定公司運作的頂部,底部,領導和底部約束滾動型 2.To滾動視圖內包裝視圖給頂部,底部,領先和底部以及與父視圖的寬度相等。 3. 非常重要的步驟:將所有內部UI元素與前導,尾隨,頂部,底部和高度鏈接。特別爲最後elemnt記得添加底部以及高度和尾部也