stay iOS Developing learning ,UIScrollView Is an important control that can't get around .
But relative to Android Of ScrollView,iOS The usage of this scroll control is ten thousand times more complex ...
The main thing is that most of the video tutorials you can find are about UIScrollView A tutorial for , Is to use Frame Layout . No use found AutoLayout A tutorial on layout .. Only read the text tutorial to learn , Then sum it up for yourself .
StoryBoard Operation layout
stay storyboard in , Drag into one UIScrollView, Then open the... On the right show the size inspector, Uncheck content layout guides, Then set the UIScrollView The upper, lower, left and right constraints of are 0, Then check again content layout guides
Find out here Xcode Prompt constraint error , The reason is because UIScrollView We need to have a ContentView To determine your scrolling area .
So drag another UIView To UIScrollView On , Then change the name to this UIView by ContentView, Right click and drag this UIView To UIScrollView Of content layout guides On , Hold down shift Check the first four constraints , Give Way UIScrollView and ContentView Four edges establish constraints .
Then adjust ContentView Constrained constant Value ,Xcode The constraints created by default don't seem perfect , It is calculated automatically by default ContentView Initial size of .
Adjust these to 0
It's best to set these settings , The red dot of constraint error still does not disappear ... Click to open it .
explain UIScrollView The rolling direction cannot be determined according to the width and height . You need to set the width and height . Because it's a mobile device . Default should be Y Axis roll .
Then set the width equal to UIScrollView Width . Set the height to a higher value , You can scroll
Drag with the right mouse button ContentView To Frame Layout Guides On , Then constrain ContentView and Frame Layout Guides The width is the same .
Then set it separately ContentView The height of 1000, The red dot of constraint error is gone , Run the program , A scroll bar appears on a white background , You can slide up and down .
Use pure code layout
Thinking and using StoryBoard equally . It's just described in code
let sv = UIScrollView();
sv.translatesAutoresizingMaskIntoConstraints = false
sv.backgroundColor = UIColor.systemGray;
sv.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
sv.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
sv.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
sv.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true let contentView = UIView()
contentView.translatesAutoresizingMaskIntoConstraints = false
contentView.layer.name = "contentView"
contentView.backgroundColor = UIColor.white
contentView.leadingAnchor.constraint(equalTo: sv.contentLayoutGuide.leadingAnchor).isActive = true
contentView.topAnchor.constraint(equalTo: sv.contentLayoutGuide.topAnchor).isActive = true
contentView.trailingAnchor.constraint(equalTo: sv.contentLayoutGuide.trailingAnchor).isActive = true
contentView.bottomAnchor.constraint(equalTo: sv.bottomAnchor).isActive = true
contentView.widthAnchor.constraint(equalTo: sv.frameLayoutGuide.widthAnchor).isActive = true
contentView.heightAnchor.constraint(equalToConstant: 1000).isActive = true
Welcome to my official account and communicate with me
- iOS Development of UIScrollView Of frame、contentSize、contentOffset and contentInset attribute
ios The drop-down image becomes bigger http://blog.csdn.net/mad2man/article/details/14169197 IOS in UIScrollView Of frame.contentSiz ...
- IOS Development of UIScrollView
One .UIScrollView The problem of boundary treatment in China : bounds attribute : (1) When bounces Property is set to YES when , When UIScrollView When the picture slides to the boundary, it will bounce , like Linux The jelly effect in ...
- IOS Development of UIScrollVIew Application
UIScrollView You can see everything in one interface , And you don't have to worry about what's on the screen , When beyond, you can turn to the next page to browse . #pragma mark - UIScrollViewDelega ...
- Li Hongqiang iOS Development of iOS Good article collection
Li Hongqiang iOS Development of iOS Good article collection This article collects technical articles forwarded by friends or written by themselves , If you also have relevant good articles , Welcome to leave a message , When there are many good articles , I will classify these good articles article sketch date Live broadcast service configuration Use ng ...
- Li Hongqiang IOS Development of iOS Good project collection
Li Hongqiang IOS Development of iOS Good project collection Here is a collection of some interesting and practical frameworks or projects , It will be constantly updated project sketch date SCTableViewCell Similar to QQ Sideslip delete Cell Of Demo 201501 ...
- iOS Development of MVVM Application in the project
The purpose of writing this blog today is to throw a brick to attract jade , I want to share my thoughts with you , Learn from each other , I hope you can criticize and correct the deficiencies in the blog . The content of this blog follows the style of previous blogs , It's also mainly dry goods , Now and then I pull the salted eggs ( ha-ha ~ Don't work hard and start blogging again ...
- Li Hongqiang iOS Development of RunLoop Principle and core mechanism of
Li Hongqiang iOS Development of RunLoop Principle and core mechanism of To make iOS I haven't studied it in depth since RunLoop, Very ashamed . Just a while ago, I was responsible for the performance optimization project , Need to use RunLoop Do performance optimization and performance testing , Take this opportunity to delve into ...
- iOS Development of Socket Communication practice --Request Request packet encoding module
In fact, iOS Many applications are developing , Most of the network communication is http/https agreement , Unless there is a special need to use Socket The network protocol carries on the network number According to the transmission , At this time iOS The client needs a good third party CocoaAsyncS ...
- iOS Development of UISearchBar On
iOS Development of UISearchBar On UISearchBar It's also iOS Develop one of the common controls , Click inside to see the attributes barStyle.text.placeholder wait . But these attributes are obviously insufficient to meet our needs ...
- iOS Development of UIImage Scale proportionally
iOS Development of UIImage Scale proportionally Comments are great After the comments were launched , Sure enough, many people make complaints about it . Thank you for your support and love , If there's something you can't do , Please ask Hai Han. . After all, my strength alone is limited , I will try my best to prepare some dry goods for you ...
- C++ operation XML file Use MSXML.DLL
Use MSXML.DLL Reading and writing XML; Add... At the top of the file #import "msxml3.dll"; using namespace MSXML2; // These two sentences are , Generate... In the folder of the program ...
- ajax Be careful
1. To send data to the server , You should use POST Method , To retrieve data from the server , You should use GET Method . 2.ajax Complete parameters , url Address sent http://localhost/default.a ...
- SQL Server system time
getdate() function : Get the current date and time of the system . The return value is datetime Type of . usage :getdate() Example : select getdate() as dte,dateadd(day,-1,ge ...
- java.exe routing problem
Because it needs to be replaced JDK edition , Naturally, it has to be reset JAVA_HOME environment variable , But after setting up, I found something strange , function java -version It's still the original version , Without rhyme or reason , Finally, I put JAVA_HOME The environment variable is deleted java ...
- [Elasticsearch] Proximity matching ( One ) - Phrase matching and slop Parameters
This article is translated from Elasticsearch The official guide to Proximity Matching chapter . Proximity matching (Proximity Matching) Used TF/IDF Standard full-text search will document , Or at least every in the document ...
- maven Installation and environment configuration of
One . download maven Apache Maven Download address :http://maven.apache.org/download.cgi Two .maven Installation Unzip the downloaded installation file to d Packing directory can be ( Of course , this ...
- Wu Enda's machine learning notes 25- Model representation of neural networks 2(Model Representation of Neural Network II)
( FORWARD PROPAGATION ) Coding relative to using cycles , The vectorization method will make the calculation easier . Take the above neural network as an example , Try to calculate the value of the second layer : This is only a calculation for a training example in the training set . If I ...
- 【 Reprint 】 Reinforcement learning ( 11、 ... and ) Prioritized Replay DQN
Original address : https://www.cnblogs.com/pinard/p/9797695.html ------------------------------------------------ ...
- stay consul Registered on web service
1. establish web service IDEA->File->New->Project->Empty Project,project name The name provider, Click on finish 2. establish ...
- installed as After that, it is suggested that NO JVM installation found.....
Pictured . solve : stay AS Installation directory , Find the corresponding program [jdk Open as many bits as you want ]