iosiOS DeveloperiOS 开发每天分享优质文章

UIScrollView 几点总结

2016-12-02  本文已影响0人  无尽思绪

UIScrollView的常见属性

@property (nonatomic) CGPoint contentOffset;
@property (nonatomic) CGSize contentSize;
@property (nonatomic) UIEdgeInsets contentInset;

UIScrollView的其他属性

@property (nonatomic) BOOL bounces;
// 取消回弹效果
self.scrollView.bounces = NO;
@property (nonatomic, getter = isScrollEnabled) BOOL scrollEnabled;
@property (nonatomic) BOOL showsHorizontalScrollIndicator;
@property (nonatomic) BOOL showsVerticalScrollIndicator;

UIScrollView的基本使用

self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
@property(nonatomic) UIScrollViewIndicatorStyle  indicatorStyle; // default is UIScrollViewIndicatorStyleDefault
// 回弹效果
@property(nonatomic) BOOL bounces;  // default YES. if YES, bounces past edge of content and back again
@property(nonatomic)  UIEdgeInsets contentInset; // default UIEdgeInsetsZero. add additional scroll area around content
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;  // animate at constant velocity to new offset

UIScrollView代理

// 只要UIScrollView滚动就会调用
// 系统会自动调用这些方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView; // any offset changes
// 只要用户准备开始拖拽就会调用
// called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
// 用户停止拖拽(已经松手)
// 但是并不意味着UIScrollView已经停止滚动了,每次调用此方法时,系统都会传入一个当前是否有惯性的参数(decelerate)
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
// UIScrollView停止减速
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;      // called when scroll view grinds to a halt
// 在开发中如果需要监听scrollView滚动是否停止可以这样写
- (void)scrollViewDidEndDragging:(nonnull UISrollView *)scrollView willDecelerate:(BOOL)decelerate
{
  if(decelerate == NO){
    [self scrollViewDidEndDecelerating:scrolView];
  }else{
  }
}
- (void)scrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView
{
  // 在这里面写scrollView停止时需要做的事情
  NSLog(@"UIScrollView停止滚动了");
}

UIScrollView缩放

self.sc.maximumZoomScale = 2.0;
self.sc.minimumZoomScale = 0.5;
// 代理方法
// 大部分代理方法是由控件名开头,小部分不是
// 在此方法中告诉UIScrollView要缩放哪一个控件
- (UIView *)viewForZoomingInScrollView:(nonnull UISCrollView *)scrollView{
  return 需要缩放的图片
}
// 缩放的过程中调用
- (void)scrlooViewDidZoom:(nonnull UIScrollView *)scrolView{
}
// 缩放结束时调用
- (void)scrollViewDidEndZooming:(nonnull UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale{
}

UIScrollView

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width + 100, self.scrollView.frame.size.height + 100);

UIScrollView图片轮播器

原文链接:http://www.jianshu.com/p/6fc9ffdca1f1

上一篇下一篇

猜你喜欢

热点阅读