【问题标题】:Why uiscrollview doesn't make visible the contentOffset change?为什么 uiscrollview 不显示 contentOffset 更改?
【发布时间】:2011-03-24 23:10:44
【问题描述】:

大家好,我对 uiscrollview 有疑问。 当我按下按钮通过 UIView 动画更改 contentOffset scollview 时,我有这样的东西:


NSLog(@"%@\n %f %f", scroll, scroll.contentOffset.x, scroll.contentOffset.y);    
[UIView beginAnimation:@"anima" context:nil];
[UIView setAnimationDuration:0.5];
scroll.contentOffset = CGPointMake(0,index * scroll.frame.size.height;
[UIView commitAnimations];
NSLog(@"%@\n %f %f", scroll, scroll.contentOffset.x, scroll.contentOffset.y);

在这些指令更改之前和之后创建一个日志 cotentOffSet,显然滚动视图是一个现有实例,因此它与 nil 不同。 问题是屏幕不会改变不移动的偏移滚动视图。
我在代码的其他部分和其他滚动视图中做同样的事情,但它工作得很好。
我也试过了:


[scroll setContentOffset:CGPointMake(0, index * currentVerticalScrollView.frame.size.height) animated:YES] ;

但也不会改变!
为什么它不起作用?

【问题讨论】:

  • 你当时确定在主线程吗?

标签: iphone objective-c ios ipad uiscrollview


【解决方案1】:

您是否确保最初在滚动时调用setContentSize:,足够大以允许滚动偏移?

如果是这样,它可能需要[scroll setNeedsDisplay] 来试一试!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 2011-03-21
    相关资源
    最近更新 更多