怎么让scrollView禁止惯性滑动

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 

if (decelerate) 

dispatch_async(dispatch_get_main_queue(), ^{ 
printf("STOP IT!!\n"); 
[scrollView setContentOffset:scrollView.contentOffset animated:NO]; 
}); 

}


ScrollView图片分页显示-简单

#import "CXBViewController.h"#define pCount 5 // 分页显示的图片张数,或者是页数
@interface CXBViewController () <UIScrollViewDelegate>
{  UIPageControl *_pageControl;
}
@end
@implementation CXBViewController
- (void)viewDidLoad
{  [super viewDidLoad];    
// 为scrollView添加图片 
 // 设置图片的宽和高  
 CGFloat w = self.view.frame.size.width;  
 CGFloat h = self.scrollView.bounds.size.height;  
 for (int i = 0; i < pCount; i++) {    
 UIImageView *imageView = [[UIImageView alloc] init];
     // 定义图片名,通过循环把所有的图片添加到scrollView中   
      NSString *imageName = [NSString stringWithFormat:@"img_%02d", i + 1 ];    
      imageView.frame = CGRectMake(i*w, 0, w, h);    imageView.image = [UIImage imageNamed:imageName];   
       [self.scrollView addSubview:imageView];  }  
       // contentSize的y值为0表示在垂直方向上不做滚动  
       self.scrollView.contentSize = CGSizeMake(pCount * w, 0); 
        // 禁用滚动条,只设置水平方向的滚动条即可,竖直方向的滚动范围是0,所以没必要设置  
        self.scrollView.showsHorizontalScrollIndicator = NO;   
         // 设置分页,这个分页的原理实际上是按照ScrollView的大小分页的,这里的图片的宽由于和ScrollView的宽式一样的所以刚好分页显示图片了  
         _scrollView.pagingEnabled = YES;    
         // 添加分页表示符  UIPageControl *pageControl = [[UIPageControl alloc] init]; 
          // 让它居中,就设置center属性  pageControl.center = CGPointMake(w * 0.5, h - 20); 
           pageControl.bounds = CGRectMake(0, 0, 120, 20);  
           // 设置显示的点的个数  pageControl.numberOfPages = pCount;  
           // 禁止点击  pageControl.enabled = NO; 
            pageControl.pageIndicatorTintColor = [UIColor grayColor];  
            pageControl.currentPageIndicatorTintColor = [UIColor brownColor]; 
             _pageControl = pageControl; 
              // 这里添加到view中,不能添加到ScrollView中,否则会随着滚动而消失  
              [self.view addSubview:pageControl];      
              // 监听ScrollView的滚动,来告诉页码显示 
               // 设置代理  _scrollView.delegate = self;
}
// 实现协议里的监听滚动的方法,这个方法是ScrollView在滚动时,会被调用
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{  
// 用contentOffset来计算当前的页码  
int pageCount = self.scrollView.contentOffset.x/self.scrollView.bounds.size.width; 
 _pageControl.currentPage = pageCount; 
  }
  @end


转载于:https://my.oschina.net/daniels/blog/550893

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值