UIScrollView设备上的奇怪行为

时间:2014-01-14 22:02:27

标签: ios objective-c uiscrollview ios-simulator device

我在我的应用程序中实现了一个'UIScrollView',如下所示:

scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(59.0, 116, 180, 145)];
[scroller setBackgroundColor:[UIColor clearColor]];
[scroller setPagingEnabled:NO];
[scroller setScrollEnabled:NO];
[scroller setDelegate:self];
if (![scroller isDescendantOfView:MyUIView])
{
    [MyUIView addSubview:scroller];
}

要滚动,我添加了一个'UIButton',其执行:

Y = Y + 200;
[scroller setContentOffset:CGPointMake(Y, 0) animated:YES];
NSLog(@"Scroll : %f", scroller.contentOffset.x);

在'模拟器'上,这有效!但是在设备上,scroller.contentoffset.x给了我一些随机值,所以移动我的内容真奇怪......模拟器和我的设备处于'发布'模式

我真的不明白为什么这不起作用,因为在先前的应用程序中,它运行得很好。

感谢您的帮助!

编辑:

做的时候:

[scroller setContentOffset:CGPointMake(Y, 0) animated:NO];

它可以正常工作

做的时候:

[scroller setContentOffset:CGPointMake(Y, 0) animated:YES];

它给了我随机值,并做了一些错误的事情

2 个答案:

答案 0 :(得分:1)

尝试使用Scroll rect转换为可见方法

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

传递您感兴趣的矩形。还要确保已设置滚动视图的contentSize。

答案 1 :(得分:0)

我找到了解决方案,它看起来像是一个错误。 Here是解决方案。

[UIView animateWithDuration:.25 animations:^{
self.scrollView.contentOffset = ...;
}];
相关问题