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