0

控制上下滚动的按钮有问题。当我第一次单击向上按钮但第二次滚动视图不向上滚动时,它工作正常(向上滚动)。我做错了什么?这是代码:

创建滚动:

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(38, 5, 90, 280)];
[scrollView setContentSize:CGSizeMake(90, 950)];
[scrollView setScrollEnabled: NO];
[imageView addSubview:scrollView];
[scrollView setShowsHorizontalScrollIndicator:NO];
[scrollView setShowsVerticalScrollIndicator:NO];

按钮动作:

-(IBAction)upButtonPress:(id)sender{

NSLog(@"UP");
[scrollView setContentOffset:CGPointMake(0, self.scrollView.frame.origin.y + 95)];

 }
-(IBAction)downButtonPress:(id)sender{

NSLog(@"DOWN");
[scrollView setContentOffset:CGPointMake(0, self.scrollView.frame.origin.y - 95)];

 }
4

2 回答 2

0

相应地在您的按钮操作上使用它:

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

其中 Y 是 的值scrollView.contentOffset.y + scrollView.contentSize.height

于 2013-06-14T07:39:42.180 回答
0

您每次都使用滚动视图框架原点的 y 值。你应该scrollView.contentOffset.y改用。

-(IBAction)upButtonPress:(id)sender {
    NSLog(@"UP");
    [scrollView setContentOffset:CGPointMake(0, self.scrollView.contentOffset.y + 95)];
 }

-(IBAction)downButtonPress:(id)sender {
    NSLog(@"DOWN");
    [scrollView setContentOffset:CGPointMake(0, self.scrollView.contentOffset.y - 95)];
}
于 2013-06-14T07:44:51.057 回答