Ios 以编程方式将UIScrollView从左向右滚动一次
我尝试从左向右自动滚动,但尚未成功。 我正在评估下面的表达式以改变方向(添加或减少像素),但当滚动到最终结果时,它被阻止Ios 以编程方式将UIScrollView从左向右滚动一次,ios,uiscrollview,reverse,right-to-left,Ios,Uiscrollview,Reverse,Right To Left,我尝试从左向右自动滚动,但尚未成功。 我正在评估下面的表达式以改变方向(添加或减少像素),但当滚动到最终结果时,它被阻止 (xContentSize - xOffset) >= CGRectGetWidth(_scroll.bounds) 或 有什么想法吗?试试这个: float w = scrollView.frame.size.width; float h = scrollView.frame.size.height; float newPosition = scrollView.c
(xContentSize - xOffset) >= CGRectGetWidth(_scroll.bounds)
或
有什么想法吗?试试这个:
float w = scrollView.frame.size.width;
float h = scrollView.frame.size.height;
float newPosition = scrollView.contentOffset.x+w;
CGRect toVisible = CGRectMake(newPosition, 0, w, h);
[scrollView scrollRectToVisible:toVisible animated:YES];
手动设置所需位置尝试以下操作:
float w = scrollView.frame.size.width;
float h = scrollView.frame.size.height;
float newPosition = scrollView.contentOffset.x+w;
CGRect toVisible = CGRectMake(newPosition, 0, w, h);
[scrollView scrollRectToVisible:toVisible animated:YES];
手动设置所需位置最后,我得到了解决方案 每4.0秒使用一次NSTimer
[UIView animateWithDuration:3.0
animations:^{
if (_direction == 0) {
_scroll.contentOffset = CGPointMake((_scroll.contentSize.width - CGRectGetWidth(_scroll.frame)), 0.0);
}else{
_scroll.contentOffset = CGPointMake(0.0, 0.0);
}
} completion:^(BOOL finished) {
_direction = !_direction;
}];
最后,我找到了解决办法 每4.0秒使用一次NSTimer
[UIView animateWithDuration:3.0
animations:^{
if (_direction == 0) {
_scroll.contentOffset = CGPointMake((_scroll.contentSize.width - CGRectGetWidth(_scroll.frame)), 0.0);
}else{
_scroll.contentOffset = CGPointMake(0.0, 0.0);
}
} completion:^(BOOL finished) {
_direction = !_direction;
}];
Swift 4-向右滚动70px,然后向后向左滚动(用于提示用户在
UIScrollView
UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [.curveEaseInOut, .allowUserInteraction, .autoreverse], animations: {
self.scrollView.contentOffset.x += 70
}) { [unowned self] _ in
self.scrollView.contentOffset.x = 0
}
Swift 4-向右滚动70px,然后向后向左滚动(用于提示用户在
UIScrollView
UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [.curveEaseInOut, .allowUserInteraction, .autoreverse], animations: {
self.scrollView.contentOffset.x += 70
}) { [unowned self] _ in
self.scrollView.contentOffset.x = 0
}
你想用什么来表示“它被阻止了”?Sovanarith,卷轴向右移动,但当它到达最后一个位置时,向左移动,然后无限期向右移动(它被阻止了)。你能给我看一下你对scrollview的计算吗?你想用什么来表示“它被阻止了”?sovannarith,卷轴向右移动,但当到达终点时,向左移动,然后无限期向右移动(被阻止)你能告诉我你对scrollview的计算吗?我需要在哪里写这个。我的意思是在哪个scroll view委托方法中。我在scrollviewdidscroll中写了,但没有工作。我的意思是在哪个scroll view委托方法中。我在scrollviewdidscroll中写了,但没有工作