"iOS Dev-53" Case study: Core usage of ScrollView and solutions that cannot be scrolled

Source: Internet
Author: User

Case Effect:



(1) The main thing is to practice the use of scrollview. All the other elements in the interface are basically uiview and UIButton piled up.


(2) The main use of code to achieve, of course, you can first use storyboard drag a scrollview out. Note that the need to scroll needs to be placed in the ScrollView, pay attention to the hierarchical relationship.


(3) We want to use this scrollview in our code so we can drag and drop to form a variable, and the code is in VIEWCONTROLLER.M:

--Set the most important three properties of ScrollView as follows, marked with comments.

--The maximum minimum x and Y values for a control can be cgrectgetmaxy by means of a method, but a parameter such as a frame needs to be passed.

#import "ViewController.h" @interface Viewcontroller () @property (weak, nonatomic) Iboutlet Uiscrollview *scrollview;@ Property (weak, nonatomic) Iboutlet UIButton *beherebtn; @end @implementation viewcontroller-(void) viewdidload {    // Determine how wide the ScrollView can roll    self.scrollview.contentsize=cgsizemake (320,cgrectgetmaxy (self.beHereBtn.frame) +10);    Increase the rolling area around ScrollView    self.scrollview.contentinset=uiedgeinsetsmake (0, 0);    Sets the movement position of the control in the ScrollView    self.scrollview.contentoffset=cgpointmake (0, -64);    [Super Viewdidload];    Do any additional setup after loading the view, typically from a nib.} @end

(4) Note: Generally there is no scrolling situation, should learn to self-troubleshooting:

--Check to see if you forgot to define the control as a control variable.

It is possible to layout the ScrollView, but forget to set its Contentsize property, or This property is set too small, not scrollview frame large, also can not scroll.

-it's possible that auto layout is messing up and you can turn this option off in storyboard.


"iOS Dev-53" Case study: Core usage of ScrollView and solutions that cannot be scrolled

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.