Ios: similar to the reading slide effect in the [ONE] Application

Source: Internet
Author: User

1. desired effect: When you browse the article, when you slide down, the navigationBar and toolbar are hidden. When you reach the end, move up and the navigationBar and toolbar are displayed again. 2. Idea: first, webview is used to display the article. We all know that webview contains scrollview. This makes it easy. We can use scrollview to implement it. The Code is as follows: copy the Code # pragma mark-UIScrollViewDelegate-(void) scrollViewDidScroll :( UIScrollView *) scrollView {int currentPostion = scrollView. contentOffset. y; if (currentPostion-lastPostion> kSlide & currentPostion> 0) {lastPostion = currentPostion; // reset frame [UIView animateWithDuration: kAnimationTime animations: ^ {CGRect rc = self. navigationController. navigationBar. frame; self. navigationController. navigationBar. frame = CGRectMake (0,-CGRectGetHeight (rc), CGRectGetWidth (rc), CGRectGetHeight (rc); rc = self. toolbar. frame; self. toolbar. frame = CGRectMake (0, [UIScreen mainScreen]. bounds. size. height, CGRectGetWidth (rc), CGRectGetHeight (rc); self. webView. frame = CGRectMake (0, 0, [UIScreen mainScreen]. bounds. size. width, [UIScreen mainScreen]. bounds. size. height) ;}] ;}else if (lastPostion-currentPostion> kSlide & (currentPostion <= scrollView. contentSize. height-scrollView.bounds.size.height-kSlide) {lastPostion = currentPostion; // reset frame [UIView animateWithDuration: kAnimationTime animations: ^ {CGRect rc = self. navigationController. navigationBar. frame; self. navigationController. navigationBar. frame = CGRectMake (0, 0, CGRectGetWidth (rc), CGRectGetHeight (rc); rc = self. toolbar. frame; self. toolbar. frame = CGRectMake (0, [UIScreen mainScreen]. bounds. size. height-CGRectGetHeight (rc), CGRectGetWidth (rc), CGRectGetHeight (rc); self. webView. frame = CGRectMake (0, CGRectGetHeight (self. navigationController. navigationBar. frame), [UIScreen mainScreen]. bounds. size. width, [UIScreen mainScreen]. bounds. size. height-CGRectGetHeight (self. navigationController. navigationBar. frame)-CGRectGetHeight (rc) ;}] ;}}

Related Article

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.