我想在按钮点击时将内容滚动到滚动视图

时间:2013-10-26 06:27:30

标签: ios iphone

我已经添加了这些代码以将内容滚动到滚动视图中,但是我的滚动视图fram正在从右向左移动而不是内容。 我的代码在这里..     in this image there are two buttons both side of scroll view

-(IBAction)leftbtnclick:(id)sender
{
    NSLog(@"left clicked");
    CGRect basketTopFrame = nameContainerScrollView.frame;
    basketTopFrame.origin.x = 115;
    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ nameContainerScrollView.frame = basketTopFrame; } completion:^(BOOL finished){ }];


}

-(IBAction)rightbtnclick:(id)sender
{
    NSLog(@"right clicked");
    CGRect napkinBottomFrame = nameContainerScrollView.frame;
    napkinBottomFrame.origin.x = 0;
    [UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ nameContainerScrollView.frame = napkinBottomFrame; } completion:^(BOOL finished){/*done*/}];

}

1 个答案:

答案 0 :(得分:1)

您可以通过此行代码将scrollView滚动到特定位置/偏移

[addFeedsScroll scrollRectToVisible:CGRectMake(0, 262, addFeedsScroll.frame.size.width, addFeedsScroll.frame.size.height) animated:YES];

注意: - addFeedsScroll为UIScrollView