Summary of basic usage of UIScrollView scroll view in iOS application development
- 2020-05-15 02:11:09
- OfStack
I encountered a problem in the project development. I directly created an UIScrollerView on UIViewController and added UIScrollerView to UIViewController as a subview.
In addition, a component of UISlider was added to UIScrollerView. In the process of gesture sliding, it is difficult to slide to UISlider, and UIScrollerView often scrolls when sliding.
The UISlider control doesn't slide, which is annoying.
Go to the Internet to understand the details of UIScrollerView 1, finally thoroughly understand the problem where
The following is the summary of 1 senior, because I think it is not as detailed as his summary
UIScrollView overloads the hitTest method, when finger touch, UIScrollView will intercept all event, and then wait for 150ms. During this time, if no finger is moving, UIScrollView will send tracking event to the subview at the end of the time, and will not slide itself. When the finger moves before the end of time, UIScrollView slides to cancel sending tracking.
It seems to be the UIScrollView problem. Directly drag UISlider. At this time, touch is within 150ms. UIScrollView will think that it is dragging itself, thus intercepting event, and UISlider cannot accept event sliding. But as long as you hold UISlider1 and drag again, touch takes more than 150ms, so the event is sent to UISlider.
During this period, I tried several methods, but only one of them worked, which was to rewrite hitTest method of UIScrollView: when sliding UISlider, make UIScrollView unable to slide.
However, there is another problem. My UIScrollerView directly inherits UIScrollerView, and UIScrollerView's hitTest method cannot be overridden in UIViewController, so I need to recreate an view, inherit UIScrollerView, rewrite the above method, and then import UIViewController, which can be easily implemented.
Here's a look at some of the more common USES of 1 in UIScrollerView that are included in the comments:
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor = [UIColor redColor];
// Whether to support the sliding top
// scrollView.scrollsToTop = NO;
scrollView.delegate = self;
// Set content size
scrollView.contentSize = CGSizeMake(320, 460*10);
// Whether the rebound
// scrollView.bounces = NO;
// Whether the paging
// scrollView.pagingEnabled = YES;
// Whether the scroll
// scrollView.scrollEnabled = NO;
// scrollView.showsHorizontalScrollIndicator = NO;
// Set up the indicator style
// scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
// Set the content's edge and Indicators The edge
// scrollView.contentInset = UIEdgeInsetsMake(0, 50, 50, 0);
// scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 50, 0, 0);
// Prompt the user ,Indicators flash
[scrollView flashScrollIndicators];
// Are you simultaneously moving ,lock
scrollView.directionalLockEnabled = YES;
[self.view addSubview:scrollView];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, 320, 40)];
label.backgroundColor = [UIColor yellowColor];
label.text = @" learning scrolleview";
[scrollView addSubview:label];
[label release];
}
#pragma mark -
/*
// return 1 Zoom in or zoom out views
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
}
// Start zooming in or out
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:
(UIView *)view
{
}
// At the end of the zoom
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
}
// The view has been zoomed in or out
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScrollToTop");
}
*/
// Whether sliding to the top is supported
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
return YES;
}
// This method is called when you slide to the top
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScrollToTop");
}
// scrollView Has been sliding
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScroll");
}
// scrollView Began to drag
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"scrollViewWillBeginDragging");
}
// scrollView The end of the drag
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"scrollViewDidEndDragging");
}
// scrollView Start slowing down (note that the following two methods differ from the above two)
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewWillBeginDecelerating");
}
// scrollview Slowing down to stop
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidEndDecelerating");
}