UIScrollView 动画在 iOS 上不够流畅
我正在为 iPad 开发一个应用程序。
在此,我使用两个 UIScrollView 控制器。
当用户滚动第一个 ScrollView
时,第二个 ScrollView
也必须以编程方式滚动。
类似地,当用户滚动第二个 Scroll View 时,第一个 ScrollView 也需要滚动。
如何在同一个视图中处理这两个滚动视图?
我已经尝试过:
(void)scrollViewDidScroll:(UIScrollView *)scrollView; method of the UIScrollViewDelegate.
但是滚动动画不够流畅。
请向我建议任何其他方式来做到这一点。
我的代码是:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView == sub )
{
if(sub.isDragging)
{
NSLog(@"Sub");
float x = main.contentSize.width/sub.contentSize.width;
CGPoint offset = CGPointMake((sub.contentOffset.x*x), sub.contentOffset.y);
[main setContentOffset:offset animated:NO];
}
}
else if(scrollView == main)
{
if(main.isDragging)
{
float x = main.contentSize.width/sub.contentSize.width;
CGPoint offset = CGPointMake((main.contentOffset.x/x), main.contentOffset.y);
[sub setContentOffset:offset animated:NO];
}
}
}
I am developing an application for iPad.
In this, I am using two UIScrollView Controllers
.
When a user scrolls the first ScrollView
, the Second ScrollView
also has to scroll programmatically.
Similarly, when a user scrolls the 2nd Scroll View then the first ScrollView
needs to scroll.
How to handle these 2 scroll views in the same View?
I have tried this:
(void)scrollViewDidScroll:(UIScrollView *)scrollView; method of the UIScrollViewDelegate.
But the scrolling animation is not smooth enough.
Please suggest to me any other way do this.
My code is:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView == sub )
{
if(sub.isDragging)
{
NSLog(@"Sub");
float x = main.contentSize.width/sub.contentSize.width;
CGPoint offset = CGPointMake((sub.contentOffset.x*x), sub.contentOffset.y);
[main setContentOffset:offset animated:NO];
}
}
else if(scrollView == main)
{
if(main.isDragging)
{
float x = main.contentSize.width/sub.contentSize.width;
CGPoint offset = CGPointMake((main.contentOffset.x/x), main.contentOffset.y);
[sub setContentOffset:offset animated:NO];
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
setContentOffset 代替。并且设置动画为YES会更流畅!
Try to use
instead of setContentOffset. And set animated to YES it will be smoother!