我如何获得contentOffset的x位置?
这是我的代码,但在日志中总是抛出
- (void)adjustAreaScroll:(NSNotification *)notification
{
int value = [[notification object] intValue];
NSLog(@"adjustAreaScroll, %i", value);
switch (value) {
case 0:
[topScroll setContentOffset:CGPointMake(0, 0)];
break;
case 1:
[topScroll setContentOffset:CGPointMake(1024, 0)];
break;
case 2:
[topScroll setContentOffset:CGPointMake(2048, 0)];
break;
case 3:
[topScroll setContentOffset:CGPointMake(3072, 0)];
break;
}
NSLog(@"target position -----> %i", self.topScroll.contentOffset.x);
}
答案 0 :(得分:5)
CGPointMake返回一个CGPoint,它由CGFloats组成。将%i设为%f。
答案 1 :(得分:1)
NSLog(@"Offset : %@", NSStringFromCGPoint(scrollview.contentOffset.x));
或定义如下
CGFloat offSet= scrollview.contentOffset.x;
NSLog(@"Offset : %f", offset);