Program Control UIScrollView

Is there a way to programmatically control UIScrollView? As in the case of obtaining a value for its location, so how far does it scroll and something changes and its position changes, scroll it programmatically?

Hope you can help, thanks.

0
source share
4 answers

I don’t know what @Alexandergre or @JAgostoni are talking about. Scrolling in UIScrollView is very simple.

I suggest you familiarize yourself with the documentation for UIScrollView: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html

To scroll through a UIScrollView just use

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

Example:

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

This will scroll the UIScrollView with animation up to 20 along the x axis, 20 along the height and width of y and 320x480.

If you want to get information about your view (for example, which frame is visible), you should use the methods and properties from UIView, since it is the parent of UIScrollView. Check out the UIView documentation at: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

To get a visible frame, use

 myScrollView.frame; 

Do not mix it with content size

 myScrollView.contentSize; 

But as I said. Use the documentation!

+4
source

You can scroll UIScrollView with

 scrollView.contentOffset = CGPointMake(x, y); 

If you want the scroll to be animated, use UIview animation

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

To get the content offset, create a CGPoint to get the offset value:

 CGPoint value; value = scrollview.contentOffset; 
+1
source
 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]; } } } 
0
source

Yeah. Take a look at this post and let me know if this helps: http://jason.agostoni.net/2011/02/12/ipad-resize-view-to-account-for-keyboard/

This is specifically for working with the keyboard, but I explain there how to get the scroll position and set it, etc. Of course, using Apple documentation.

-1
source

Source: https://habr.com/ru/post/926366/


All Articles