[IOS development-53] Case Study: Core usage of scrollView and solutions that cannot be rolled,-53 scrollview

Source: Internet
Author: User

[IOS development-53] Case Study: Core usage of scrollView and solutions that cannot be rolled,-53 scrollview

Case effect:



(1) It is mainly used to practice scrollView usage. Other elements in the interface are basically built up by UIView and UIButton.


(2) It is mainly implemented by code. Of course, you can use storyboard to drag a scrollView. Note that all the items to be rolled must be placed in scrollView. Pay attention to the hierarchical relationship.


(3) We need to set this scrollView in the code, so drag and drop to form a variable. The code is in ViewController. m:

-- Set the three most important attributes of scrollView as follows, which are marked with comments.

-- To obtain the maximum, minimum, and Y values of a control, you can use the CGRectGetMaxY method. However, you must pass a frame parameter.

# Import "ViewController. h "@ interface ViewController () @ property (weak, nonatomic) IBOutlet UIScrollView * scrollView; @ property (weak, nonatomic) IBOutlet UIButton * beHereBtn; @ end @ implementation ViewController) viewDidLoad {// determine the range of self that scrollView can scroll. scrollView. contentSize = CGSizeMake (320, CGRectGetMaxY (self. beHereBtn. frame) + 10); // Add the scroll area self around the scrollView. scrollView. contentInset = UIEdgeInsetsMake (64, 0, 49, 0); // set the position of the control in scrollView to self. scrollView. contentOffset = CGPointMake (0,-64); [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} @ end

(4) Note: In general, you should learn to troubleshoot the problem:

-- Check whether you forget to define the control as a control variable.

-- It may be because the scrollView is laid out, but the contentSize attribute is not set, or this attribute is too small, and the frame size of the scrollView is not large, and cannot be rolled.

-- Auto Layout may be messy. You can disable this option in storyboard.



IOS developers know why the scrolling page cannot be achieved after the UIWebView is embedded in ScrollView?

To achieve horizontal sliding of scrollview, the frame of scrollview is required. size. width is smaller than the Contentsize of scrollview. width is irrelevant to the increase of UIWebview. You need to set the contentsize of scrollView. the width is greater than its frame. size. width.

Scrollview for ios development cannot be moved horizontally

The contentSize attribute determines the size of the area where _ scrollview can be rolled. Your image size is 1600*1200 pixels. You can try it.
_ Scrollview. contentSize = CGSizeMake (1600 *). You can see the left and right slides.
_ ScrollView. showsHorizontalScrollIndicator = NO; the role of this sentence is to display the scroll bar, not to answer.

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.