【问题标题】:Why is my UIScrollView not appearing?为什么我的 UIScrollView 没有出现?
【发布时间】:2013-03-15 17:55:56
【问题描述】:

我正在尝试将包含 UIScrollView 的 UIView 子类化。这是我正在使用的代码:

UIViewSubclass.h

 @property (nonatomic, retain) UIScrollView *scroll;

UIViewSubclass.m

 @synthesize itemScrollView;

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {

    [self setUpScrollViewWithIdentifier:@"id"];
}
return self;
}

-(void)setUpScrollViewWithIdentifier:(NSString*)scrollViewID {

NSLog(@"Setting up Scroll View with the id of: %@",scrollViewID); //This is working

scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 90)];

//Subview of the scroll view
UIView *test = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
test.backgroundColor = [UIColor blueColor];
[scroll addSubview:test];

[self addSubview:scroll]; // Adds the scrollview to the UIView
 NSLog(@"Subviews: %@",self.subviews);
}

ViewController.h

  #import "UIViewSubclass.h"

  IBOutlet UIViewSubclass *menuView;

查看控制器.m

- (void)viewDidLoad
 {
menuView = [[UIViewSubclass alloc]init];
[super viewDidLoad];
// Do any additional setup after loading the view.
}

我还在情节提要中将视图链接起来,并将视图的类设置为 UIViewSubclass,但由于某种原因,滚动视图不会出现。但是当我检查这个 NSLog 时:

 NSLog(@"Subviews: %@",self.subviews);

它在调试器中给了我这个:

Subviews: (
"<UIScrollView: 0x1d5a20e0; frame = (0 0; 320 90); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1d5a2420>; layer = <CALayer: 0x1d5a1c60>; contentOffset: {0, 0}>"
 )

那我做错了什么?

【问题讨论】:

    标签: uiview uiscrollview storyboard subclass


    【解决方案1】:
    scroll.contentSize = fooSize;
    

    可能是你错过的。

    【讨论】:

      猜你喜欢
      • 2013-07-21
      • 2021-07-30
      • 2015-09-04
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      相关资源
      最近更新 更多