2011-03-04 57 views
0

是否有編程控制UIScrollView的方法?如同爲它的位置獲取價值,那麼滾動多少東西並改變它的位置,以編程方式滾動它?編程控制UIScrollView

希望你能幫忙,謝謝。

回答

4

我不知道@Alexandergre或@JAgostoni中的任何一個是t一直在聊。在UIScrollView中滾動非常簡單。

我建議你看一看的UIScrollView中的文檔: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html

要滾動一個UIScrollView,只需使用

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated 

例子:

[myScrollView scrollRectToVisible:CGRectMake(20, 20, 320, 480) animated:YES]; 

這將使動畫的UIScrollView滾動到x軸上的20,y和320x480高度和寬度上的20。

如果你想獲得它自己的視圖信息(例如什麼框架可見),你應該使用UIView的方法和屬性,因爲它是UIScrollView的父對象。 退房在UIView的文檔:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

要獲得可見的框架,使用

myScrollView.frame; 

不要與內容大小

myScrollView.contentSize; 

混合起來不過,正如我所說的。 使用文檔!

-1

是的。看看這篇文章,並讓我知道它是否有幫助:http://jason.agostoni.net/2011/02/12/ipad-resize-view-to-account-for-keyboard/

這是專門爲處理鍵盤,但我在那裏解釋如何獲取滾動位置和設置等,在蘋果的文檔的幫助下, 當然。

+0

我想你回答了錯誤的問題? – pt2ph8 2011-03-05 00:14:43

+0

以爲我曾經。我鏈接的帖子引用了上面的文檔以及如何滾動UIScrollView。我應該更具體。 – JAgostoni 2011-03-05 03:18:56

1

如果你想滾動您可以scrolll使用

scrollView.contentOffset = CGPointMake(x, y); 

的UIScrollView的是動畫使用的UIView動畫

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.75]; 
[UIView setAnimationDelegate:self]; 
scrollView.contentOffset = CGPointMake(x, y); 
[UIView commitAnimations]; 

要獲得內容偏移創建一個CGPoint獲得偏移值:

CGPoint value; 
value = scrollview.contentOffset; 
+0

這是非常錯誤的。在我的帖子中看到一個例子。 – Jensen2k 2011-03-05 00:16:11

0
Try this :- 

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ 
    //NSLog(@"%f %f", scrollView.contentOffset.y, scrollView.contentSize.height); 
} 
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ 
    //NSLog(@"scrollViewDidEndDecelerating"); 
} 
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ 
    //NSLog(@"scrollViewDidEndScrollingAnimation"); 
} 
//Update the value of rol 
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ 
    if(scrollView==MainScrollVw){//Main Scroll View All Fns Start,,, 
     int rol_y= MainScrollVw.contentOffset.y; 
     //int rol_x= MainScrollVw.contentOffset.x; 

     if(rol_y>0){ 
      [UIView beginAnimations:nil context:nil]; 
      [UIView setAnimationDuration:.30]; 
      MainMenuVw.frame= CGRectMake(0 ,0 ,self.view.frame.size.width ,75); 
      [UIView commitAnimations]; 

     }else{ 
      [UIView beginAnimations:nil context:nil]; 
      [UIView setAnimationDuration:.30]; 
      MainMenuVw.frame= CGRectMake(0 ,0 ,self.view.frame.size.width ,150); 
      [UIView commitAnimations]; 

     } 
     } 
    }