ios 翻頁例子源碼

來源:互聯網
上載者:User

demo功能:ios 翻頁例子源碼。iphone 6.1測試通過。

demo說明:AppDelegate.m中又主要的頁面控制碼。MyViewController.m是翻動的頁面。

 

demo主要代碼:AppDelegate.m

 

 (void)loadScrollViewWithPage:(int)page {      if (page < 0) return;      if (page >= kNumberOfPages) return;        // replace the placeholder if necessary       MyViewController *controller = [viewControllers objectAtIndex:page];      if ((NSNull *)controller == [NSNull null]) {          controller = [[MyViewController alloc] initWithPageNumber:page];          [viewControllers replaceObjectAtIndex:page withObject:controller];          [controller release];      }        // add the controller's view to the scroll view       if (nil == controller.view.superview) {          CGRect frame = scrollView.frame;          frame.origin.x = frame.size.width * page;          frame.origin.y = 0;          controller.view.frame = frame;          [scrollView addSubview:controller.view];      }  }    - (void)scrollViewDidScroll:(UIScrollView *)sender {      // We don't want a "feedback loop" between the UIPageControl and the scroll delegate in       // which a scroll event generated from the user hitting the page control triggers updates from       // the delegate method. We use a boolean to disable the delegate logic when the page control is used.       if (pageControlUsed) {          // do nothing - the scroll was initiated from the page control, not the user dragging           return;      }      // Switch the indicator when more than 50% of the previous/next page is visible       CGFloat pageWidth = scrollView.frame.size.width;      int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;      pageControl.currentPage = page;        // load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)       [self loadScrollViewWithPage:page - 1];      [self loadScrollViewWithPage:page];      [self loadScrollViewWithPage:page + 1];        // A possible optimization would be to unload the views+controllers which are no longer visible   }  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.