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);
```
工具条被滑动到最右边

点击最右侧按钮文字,被自动左移动

重新滑动到最右侧的按钮显示
```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刷新的按钮事件。