iOS界面编程-UIScrollView
来源:互联网 发布:360 u盘数据恢复 编辑:程序博客网 时间:2024/06/06 07:18
一、介绍
UIScrollView继承自UIView,它为大于窗口大小的内容提供显示支持。用户可以通过滑动屏幕滚动其它内容还以通过手指捏放大缩小显示内容。UIScroll是一些UIKit的超类,包括UITableView及UITextView
二、相关方法和属性
1.管理内容的显示
a .设置contentView的相对于scrollView的偏移量,可以理解为scrollview当前显示区域顶点相对于frame顶点的偏移量。
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
b、设置scrollView 内容视图大小,即可显示的区域。
@property(nonatomic)CGSize contentSize
c、@property(nonatomic)UIEdgeInsets contentInset
contentInset 是scrollview中contentView.frame.origin与scrollview.frame.origin的关系,比如contentView的frame为(0,30,320,480),那么contentInset则为(0, 30),
2.管理滚动
a、@property(nonatomic,getter=isScrollEnabled)BOOL scrollEnabled 可设置是否可以滚动,默认为yes
b.@property(nonatomic,getter=isDirectionalLockEnabled)BOOL directionalLockEnabled ,设置为YES滚动某个方向时,另一个方向不能滚动。默认为NO,两个方向都可以同时滚动c、@property(nonatomic)BOOL scrollsToTop 布尔值判断滑动到顶点的手势是否可用。
d.- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated指定坐标空间可见
e。@property(nonatomic,getter=isPagingEnabled)BOOL pagingEnabled 默认NO,当设置为YES时,可用
f、@property(nonatomic)BOOL bounces,设置是否有反弹效果,默认为YES
g、@property(nonatomic)BOOL alwaysBounceVertical 设置即使内容小于scrollveiw ,水平方向总是有反弹效果,默认是NO
h、@property(nonatomic)BOOL alwaysBounceHorizontal设置即使内容小于scrollveiw ,垂直方向总是有反弹效果,默认是NO
可以由子类继承,当在显示内容按下手指时,定制默认的行为。
- (BOOL)touchesShouldBegin:(NSSet<UITouch *> * nonnull)touches withEvent:(UIEvent * nullable)event inContentView:(UIView * nonnull)view
- (BOOL)touchesShouldCancelInContentView:(UIView * nonnull)view
@property(nonatomic)BOOL canCancelContentTouches
@property(nonatomic)BOOL delaysContentTouches
@property(nonatomic)CGFloat decelerationRate
@property(nonatomic,readonly, getter=isDragging)BOOL dragging
@property(nonatomic,readonly, getter=isTracking)BOOL tracking 判断用户已经按下还没有开始拖
@property(nonatomic,readonly, getter=isDecelerating)BOOL decelerating 判断用户是否拖拽结束,但滚动还没有结束
3、管理滑动指示器
a指示器类型@property(nonatomic)UIScrollViewIndicatorStyle indicatorStyle有三种类型
b指示器@property(nonatomic)UIEdgeInsets scrollIndicatorInsets
c@property(nonatomic)BOOL showsHorizontalScrollIndicator 是否显示水平指示器,默认YES
d@property(nonatomic)BOOL showsVerticalScrollIndicator 是否显示垂直指示器,默认NO
e- (void)flashScrollIndicators
@property(nonatomic,readonly) UIPanGestureRecognizer *panGestureRecognizer
@property(nonatomic,readonly) UIPinchGestureRecognizer *pinchGestureRecognizer
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated
@property(nonatomic)CGFloat zoomScale
- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated
@property(nonatomic)CGFloat maximumZoomScale
@property(nonatomic)CGFloat minimumZoomScale
4、管理委托
@property(nonatomic,weak) id<UIScrollViewDelegate > delegate
5、管理键盘表明拖拽过程中,键盘消失的模式@property(nonatomic) UIScrollViewKeyboardDismissMode keyboardDismissMode
三实际例子
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(50, 80, 150, 300)]; scrollView.backgroundColor = [UIColor grayColor]; [scrollView setContentOffset:CGPointMake(14, 14) animated:YES]; scrollView.contentSize=CGSizeMake(600, 500); UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 500)]; contentView.backgroundColor = [UIColor greenColor]; [scrollView setContentOffset:CGPointMake(30, 0) animated:YES]; [scrollView setContentInset:UIEdgeInsetsMake(10, 10, 0, 0)];// scrollView.scrollEnabled = NO;// scrollView.directionalLockEnabled = YES; [scrollView scrollRectToVisible:CGRectMake(300, 100, 50, 50) animated:YES]; [scrollView addSubview:contentView];// scrollView.bounces= NO; [self.view addSubview:scrollView]
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 64, scrollViewWidth, scrollViewHeight)]; _scrollView.backgroundColor = [UIColor redColor]; [self.view addSubview:_scrollView]; _scrollView.contentSize = CGSizeMake(scrollViewWidth * 5, scrollViewHeight); _scrollView.pagingEnabled = YES; _scrollView.maximumZoomScale = 3; _scrollView.minimumZoomScale = 0.5; _scrollView.delegate = self; _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, scrollViewWidth * 5, scrollViewHeight)]; _contentView.backgroundColor = [UIColor greenColor]; [_scrollView addSubview:_contentView]; for (int i = 0; i < 5; i++) { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(i * scrollViewWidth , 0, scrollViewWidth, scrollViewHeight)]; if (i % 2 ==0) { view.backgroundColor = [UIColor blackColor]; }else { view.backgroundColor = [UIColor whiteColor]; } [_contentView addSubview:view]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, scrollViewWidth, scrollViewHeight)]; imageView.backgroundColor = [UIColor clearColor]; NSString *imageName = [NSString stringWithFormat:@"bg%i.png", i+1]; imageView.image = [UIImage imageNamed:imageName]; imageView.contentMode = UIViewContentModeScaleAspectFit; [view addSubview:imageView];
- iOS界面编程-UIScrollView
- iOS编程-------UIScrollView / UIPageControl
- iOS- 编程:UIScrollView的使用方法
- iOS切换到UiScrollView界面卡死
- iOS界面编程-UIActionSheet
- iOS界面编程-UITextView
- iOS界面开发之UIScrollView常见属性总结
- (ios)UIScrollView和UIPageControl来实现app的欢迎界面
- iOS UIScrollView
- IOS UIScrollView
- UIscrollview ios
- IOS UIScrollView
- IOS UIScrollView
- IOS UIScrollView
- IOS UIScrollView
- IOS UIScrollView
- IOS UIScrollView
- ios UIScrollView
- 实现三级缓存
- 关于坐标系一些知识
- Pig latin 介绍
- Linux系统安装时分区的选择(推荐)
- J-Link JTAG/SWD接口
- iOS界面编程-UIScrollView
- Java基础---集合之常用集合类的区别和联系、collections、泛型
- C语言操作符++、--学习难点
- 第二章 构造函数语意学 编译器何时合成拷贝构造函数?
- GSL wrapper example codes
- 生命周期管理流程图
- Shell下大于小于等于的特殊表示
- Dom4J操作xml文档
- maven学习问题--HibernateUtil不能初始化