UIScrollView中得Decelerating得使用

  首先在UIScrollView中仅有两个有关Decelerating的方法分别为

1.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{//指停止滑动后,scrollView仍然在移动,且移动结束的时候调用此方法

     NSLog(@"滚动停止后仍然开始滑动行为_将要结束");

    pscrollView.contentOffset = CGPointMake(0, 0);

}

2.

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

{

    NSLog(@"滚动停止后仍然开始滑动行为_将要开始");

}



在这样的一个应用中,我们利用Decelerating来实现


代码如下

- (void)viewDidLoad

{

    [super viewDidLoad];

    

    pscrollView = [[UIScrollView alloc] init];

    pscrollView.backgroundColor = [UIColor redColor];

    pscrollView.frame = self.view.frame;

    pscrollView.bounces = YES;

    pscrollView.delegate = self;

    pscrollView.contentSize = CGSizeMake(self.view.frame.size.width + 0.5, self.view.frame.size.height );

    [self.view addSubview:pscrollView];

    

    UILabel *label = [[UILabel alloc] init];

    label.backgroundColor = [UIColor purpleColor];

    label.text = @"\n\n\n\n\n\n";

   

    label.numberOfLines = [label.text length];// 实现label的竖直方向排列

    label.font = [UIFont systemFontOfSize:11];

    label.frame = CGRectMake(330, 220, 20, 100);

    [pscrollView addSubview:label];

    

    tableView = [[UITableView alloc] init];

    tableView.dataSource = self;

    tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

    [pscrollView addSubview:tableView];

}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return 20;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *ID = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    if (cell == Nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

    }

    

    cell.textLabel.text = @"hello";

    

    return cell;

}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{//指停止滑动后,scrollView仍然在移动,且移动结束的时候调用此方法

     NSLog(@"滚动停止后仍然开始滑动行为将要结束");

    pscrollView.contentOffset = CGPointMake(0, 0);

}


- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

{

    NSLog(@"滚动停止后仍然开始滑动行为将要开始");

}


当我们不用 Decelerating来实现弹回还原的话
如果用

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

{}

来实现的话,会出现闪屏现象。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值