【问题标题】:UIScrollView strange behavior on deviceUIScrollView 在设备上的奇怪行为
【发布时间】:2014-02-03 04:26:27
【问题描述】:

我在我的应用程序中实现了一个“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];

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

【问题讨论】:

  • 什么是Y?值在哪里初始化?
  • 你确定 Y 在滚动条的 contentSize 内吗?
  • Y是一个int值,初始化到viewdidload方法中。但是 nslog 给了我非常低的值,比如 10 或 30...

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


【解决方案1】:

尝试将 Scroll rect 改为可见方法

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

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

【讨论】:

  • 什么是 'MyUIView' 不应该是 'self.view' 之类的吗?
  • 它可以工作,但这与其他函数的行为相同,使用变量值滚动,而不是在模拟器上......检查编辑
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多