Implementation of Automatic scrollview scrolling in iOS

Source: Internet
Author: User

. H文[ [plain] @ interface Interface1: UIViewController {IBOutlet UIScrollView * scroller; IBOutlet UILabel * warnung;} @ property (nonatomic, retain) IBOutlet UIScrollView * scrollView ;. m file [plain]-(void) viewDidAppear :( BOOL) animated {[super viewDidAppear: animated]; CGPoint bottomOffset = CGPointMake (self. scrollView. contentOffset. x, self. scrollView. contentSize. height-self. scrollView. bounds. size. height); [self. scrollView setContentOffset: bottomOffset animated: NO]; CGPoint newOffset = self. scrollView. contentOffset; newOffset. y = 0; [self. scrollView setContentOffset: newOffset animated: YES];}-(void) viewDidLoad {[scroller setScrollEnabled: YES]; [scroller setContentSize: CGSizeMake (320,420)]; [super viewDidLoad]; use setContentOffset: animated: [plain] UIScrollView * scrollView = ...; CGPoint newOffset = scrollView. contentOffset; newOffset. y = 0; [scrollView setContentOffset: newOffset animated: YES]; if you need the opening animation effect, implement [plain]-(void) viewDidLoad {[super viewDidLoad] In viewcontroller of scrollView; //... CGPoint bottomOffset = CGPointMake (self. scrollView. contentOffset. x, self. scrollView. contentSize. height-self. scrollView. bounds. size. height); [self. scrollView setContentOffset: bottomOffset animated: NO];}-(void) viewDidAppear :( BOOL) animated {[super viewDidAppear: animated]; CGPoint newOffset = self. scrollView. contentOffset; newOffset. y = 0; [self. scrollView setContentOffset: newOffset animated: YES];} slow point of movement, implemented using timer: [plain]-(void) viewDidLoad {[super viewDidLoad]; //... CGPoint bottomOffset = CGPointMake (self. scrollView. contentOffset. x, self. scrollView. contentSize. height-self. scrollView. bounds. size. height); [self. scrollView setContentOffset: bottomOffset animated: NO];}-(void) viewDidAppear :( BOOL) animated {[super viewDidAppear: animated]; CGPoint bottomOffset = CGPointMake (self. scrollView. contentOffset. x, self. scrollView. contentSize. height-self. scrollView. bounds. size. height); // set the delay time float scrollDurationInSeconds = 4.0; // calculate the timer interval float totalScrollAmount = bottomOffset. y; float timerInterval = scrollDurationInSeconds/totalScrollAmount; [NSTimer volume: timerInterval target: self selector: @ selector (scrollScrollView :) userInfo: nil repeats: YES) scrollScrollView :( NSTimer *) timer {CGPoint newScrollViewContentOffset = self. scrollView. contentOffset; // move 1px newScrollViewContentOffset up. y-= 1; newScrollViewContentOffset. y = MAX (0, newScrollViewContentOffset. y); // if it reaches the top, timer suspends if (newScrollViewContentOffset. y = 0) {[timer invalidate];} // finally set scollView's contentOffset self. scrollView. contentOffset = newScrollViewContentOffset ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.