scrollview不滚动

时间:2014-06-22 16:05:46

标签: ios objective-c uiscrollview

这是我试图实现的页面的代码。它是我正在进行的游戏的设置页面。我创建了一个包含scrollView的outerView(名为outerView),scrollView本身包含一个UIView,它包含所有主要内容,如按钮和标签。 我无法让这个scrollView在屏幕上上下滚动。任何帮助将不胜感激

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView; 
@property (weak, nonatomic) IBOutlet UIView *containerView;
    @property (weak, nonatomic) IBOutlet UIView *outerView;

    @end

    @implementation SettingsViewController

    #define music_key music
    #define sound_key sound


    -(void)viewDidLoad
    {
        [super viewDidLoad];
        [self checkValues];
        [self makeSettingsPage];
    }
    -(void)makeSettingsPage
    {
        [self.scrollView setContentMode:UIViewContentModeScaleAspectFit];

        //Content Size is size of the view inside the scrollview
        self.scrollView.contentSize = CGSizeMake(_outerView.frame.size.width,_outerView.frame.size.height);


        RoundButton *about=[[RoundButton alloc]initWithColor:color1 WithText:@"ABOUT"];
        RoundButton *privacyPolicy=[[RoundButton alloc]initWithColor:color2 WithText:@"PRIVACY \n POLICY"];
        RoundButton *termsOfUse=[[RoundButton alloc]initWithColor:color2 WithText:@"TERMS \n OF USE"];

        about.center=CGPointMake(29, 451);
        privacyPolicy.center=CGPointMake(29, 481);
        termsOfUse.center=CGPointMake(29, 511);
        self.containerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"background_letter.png"]]];

        [self.containerView addSubview:about];
        [self.containerView addSubview:privacyPolicy];
        [self.containerView addSubview:termsOfUse];
    }

1 个答案:

答案 0 :(得分:1)

setContentSize添加到viewWillAppearviewDidAppear

IBOutlet仅在视图即将显示时创建,而不是在加载后创建。

您可以通过向该行添加断点来验证这一点。滚动视图将为零。