Ios ui basics 05 and iosui05
- UIScrollView
- UIScrollView procedure
- 1. Create UIScrollView
- 2. Add the content to be displayed to UIScrollView.
- 3. Set the rolling range (contentSize) of UIScrollView)
- Note: If you want UIScrollView to be rolled, you must set a range that can be rolled.
- Several situations where scrollView cannot be rolled
- 1. The contentSize is not set.
- 2. scrollEnabled property = NO
- 3. userInteractionEnabled property = NO
- Difference between enabled and userInteractionEnabled
- Enabled: indicates that the control is unavailable.
- UserInteractionEnabled: controls cannot interact with users, that is, they cannot respond to user operations.
- Common attributes
- Go to the scroll bar
- Set the scroll bar style
self.scrollView.indicatorStyle=UIScrollViewIndicatorStyleWhite;
- By default, UIScrollView has a rebound effect. You only need to set contentSize to have a rebound effect.
self.scrollView.bounces = YES/NO;
- Even if contentSize is not set, it can have a rebound effect.
self.scrollView.alwaysBounceVertical = YES;self.scrollView.alwaysBounceHorizontal = YES;
- Set the margin contentInset
self.scrollView.contentInset = UIEdgeInsetsMake(10, 20, 30, 40);
- Set the content offset (contentOffset)
- It is actually set where scrollView is rolled
- Tell scrollView how much to move in the x direction and how much to move in the y direction
- If x is positive, move the image to the left.
- If x is negative, the image is moved to the right.
- Similarly, y is positive: the image is moved up.
- Similarly, y is a negative number: The image is moved down.
- Calculation formula: Always in the upper left corner of the control-the upper left corner of the content
- Proxy Method
- As long as you become a proxy for UIScrollView, follow the proxy Protocol to implement the methods in the Protocol
- When UIScrollView changes, the system automatically calls these proxy methods.
- As long as UIScrollView is rolled, the system will automatically call
- -(Void) scrollViewDidScroll :( UIScrollView *) scrollView
- You can call
- -(void)scrollViewWillBeginDragging:(nonnull UIScrollView *)scrollView
- The user has finished dragging. This means that the user has been released and the system has called this method. This does not mean that UIScrollView has stopped scrolling.
- -(void)scrollViewDidEndDragging:(nonnull UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
- Only when this method is executed indicates that UIScrollView has stopped scrolling.
- -(void)scrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView
+ Note: You can perform operations after UIScrollView stops rolling.
- Zoom
UIPageControl
@ Property (nonatomic) NSInteger numberOfPages; set the maximum number of pages/default is 0 @ property (nonatomic) NSInteger currentPage; set the page number // assign values to the private attribute of UIPageControl through KVC, set custom image [self. pageControl setValue: [UIImage imageNamed: @ "current"] forKeyPath: @ "_ currentPageImage"]; [self. pageControl setValue: [UIImage imageNamed: @ "other"] forKeyPath: @ "_ pageImage"];
NSTimer
// Note: nstmic should be weak // Why Should nstmic be weak, because as long as an NSTimer object is created, this object will be strongly referenced by the main thread @ property (weak, nonatomic) NSTimer * timer; // scheduledTimerWithTimeInterval: method To Call // userInfo: parameter to be passed // repeats: whether the call is repeated // call the nextPage Method of self every 2.0 seconds without passing any parameter [NSTimer scheduledTimerWithTimeInterval: 2.0 target: self selector: @ selector (nextPage) userInfo: nil repeats: YES]; // when the main thread is processing other events, take a moment to process nstammer [[[nsunloop mainRunLoop] addTimer: self. timer forMode: nsunloopcommonmodes];} // as long as the invalidate method is called, the system will remove nstdate from the main thread and destroy the NSTimer object [self. timer invalidate];