1

我已经将 a 放在了UIScrollView一个ViewControllerin 中,IB并给出了tag:1. 在viewDidLoad:,我有这个代码:

UIScrollView *scrollView = (id)[self.view viewWithTag:1];

scrollView.backgroundColor = [UIColor clearColor];
scrollView.opaque = NO;

[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)];

我有一个滑块和一个标签,ScrollView只是为了查看它是否滚动,但它根本不滚动。例如,我可以将其更改backgroundColoryellowColor,但它不会滚动。有我必须添加的方法或操作吗?请帮忙!:)

4

5 回答 5

2

不久前我遇到了同样的问题,但这成功了。

使用 -(void)viewDidAppear:(BOOL)animated { ... }

-(void)viewDidAppear:(BOOL)animated  {

    [super viewDidAppear:YES];

    scrollView.backgroundColor = [UIColor clearColor];

    scrollView.opaque = NO;

    [scrollView setScrollEnabled:YES];

    [scrollView setContentSize:CGSizeMake(320, 800)];

    [super viewDidLoad];
}

还要在标题中声明 UIScrollView

@property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
于 2013-04-25T11:29:08.280 回答
2

像这样试试

UIScrollView *scrollView = (id)[self.view viewWithTag:1];
scrollView.frame=CGRectMake(0, 0, 320, 460);
[self.view addSubview:scrollView];
scrollView.backgroundColor = [UIColor clearColor];
scrollView.opaque = NO;
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)]; 

因为当滚动视图高度越过当前视图高度时,只有它可以滚动。

于 2013-04-25T11:42:04.050 回答
0

尝试将此代码添加到viewWillAppear

UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:1];
scrollView.frame=CGRectMake(0, 0, 320, 400);
scrollView.backgroundColor = [UIColor clearColor];
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)]; 
[scrollView setUserInteractionEnabled:YES];

希望能帮到你

于 2013-04-25T15:30:56.197 回答
0

这可能是它的问题,设置 TopBar 的UIViewwith UINavigationBarfrom xib 和 BottomBar 的...这里从 XIB 首先选择 main ,然后在 Simulated metrics set NavigationBar as a TopBar 和 set frame of inUIView之后单击。Attribute InspectorUIScrollViewXIB

尝试使用下面的代码它将起作用..

[scrollView setContentSize:CGSizeMake(320, 844)];
于 2013-04-25T10:06:44.790 回答
0
scrollView.backgroundColor = [UIColor clearColor];

将其更改为红色或绿色等明亮的颜色以进行测试。

UIScrollView *scrollView = (id)[self.view viewWithTag:1];
scrollView.backgroundColor = [UIColor clearColor];

还要确保你的滚动视图不是 nil (在从[self.view viewWithtag:1]. 获取之后,否则代码看起来没问题

编辑

在界面生成器中选择滚动视图 > 转到属性编辑器 > 勾选滚动启用

启用滚动

于 2013-04-25T09:34:01.450 回答