0
点赞
收藏
分享

微信扫一扫

scrollView中的分页功能及影响


scrollView中的pagingEnabled的功能,当pagingEnabled被设置为YES时,以页为单位滑动,即自动到下一页的开始边界 。
若你自己做一个工具条(​《滑动工具条》​),文字的长度不固定并不能达到正好一屏,当pagingEnabled被设置为YES时,当你滑动工具条并点击按钮刷新ui,有几率出现工具条自动弹回的效果,导致右侧的内容不能完全显示。如用iPhone XR手机没有出问题,但是iPhone 12就出现了不期望的弹回效果。解决办法就是把pagingEnabled被设置为NO。
当然它的影响也并不是都是负面的,当你需要一次移动一个整体单位时就需要设置它使能。

.alertBackgroundView = [[UIScrollView alloc] initWithFrame:self.frame];
self.alertBackgroundView.backgroundColor = [UIColor clearColor];
[self addSubview:self.alertBackgroundView];
self.alertBackgroundView.delegate = self;
self.alertBackgroundView.pagingEnabled = NO;
self.alertBackgroundView.bounces = NO;
self.alertBackgroundView.showsHorizontalScrollIndicator = NO;
self.alertBackgroundView.scrollsToTop = NO;
self.alertBackgroundView.contentSize = CGSizeMake(self.totalWidth, self.frame.size.height);
```![在这里插入图片描述](https://img-blog.csdnimg.cn/20210520174658992.JPG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYTEyMjE2,size_16,color_FFFFFF,t_30)
工具条被滑动到最右边
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210520174725138.JPG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_20,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYTEyMjE2,size_16,color_FFFFFF,t_70)
点击最右侧按钮文字,被自动左移动
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210520174838409.JPG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYTEyMjE2,size_16,color_FFFFFF,t_70)
重新滑动到最右侧的按钮显示

```cpp
- (void)hitAction:(UIButton *)sender {
if(self.isSendindRequest)
{
return;
}
NSUInteger index = sender.tag;
if(index == self.selectIndex)
{
return;
}
[self updateBtnWithIndex:index];
if (self.hitCallback) {
self.hitCallback(sender.tag);
}
}

触发UI刷新的按钮事件。


举报

相关推荐

0 条评论