6

好的,所以我在我的应用程序中使用了 UIScrollView。我已将滚动视图放置在故事板的视图控制器中。我有几个按钮和一些标签。但是当我尝试向下滚动到底部的按钮时,滚动视图会弹回顶部。这是我使用的代码:

在 viewcontroller.h 中:

@interface ViewController : UIViewController{

    IBOutlet UIScrollView *hovscroll;
}
@end

在 viewcontroller.m 中:

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [hovscroll setScrollEnabled:YES];
    [hovscroll setContentSize:CGSizeMake(320, 1500) ];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}

@end
4

2 回答 2

1

您需要禁用分页。有(至少)两种方法可以做到这一点:

  • 在 storyboard 中,选择 UIScrollView 组件,并在“Attributes Inspector”中取消勾选“Paging Enabled”。

  • 在代码中,通过使用:

    scrollView.pagingEnabled = FALSE;
    
于 2013-05-04T20:46:24.633 回答
-1

您需要通过像这样设置滚动视图的 contentSize 属性来指定可滚动区域的大小。

[scrollview setContentSize:CGSizeMake(320, 1000)];
于 2012-12-15T19:11:05.560 回答