为什么不加入的UIScrollView对象后完全滚动?使用故事板,ARC,和X code 4.5.2 [英] Why won't UIScrollView scroll fully after adding objects? Using storyboard, ARC, and Xcode 4.5.2

查看:155
本文介绍了为什么不加入的UIScrollView对象后完全滚动?使用故事板,ARC,和X code 4.5.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我知道有矿类似的问题,但也许不准确(所以请不要标志着我失望 - 只是警告我什么的)。我已经寻找天为解决这个简单的问题。用故事板,ARC,和X code 4.5.2,我只需要放一堆标签的一个UIScrollView内,并将它垂直滚动。我试过在viewDidLoad中,viewDidAppear和viewWillAppear中设置框架的大小和内容大小的这么多的组合,但无济于事。 滚动卷轴视图完美时,有没有它的内部的,但是当我的标签添加到它,滚动滚动只有很短的一节。

So, I know there are similar questions to mine, but maybe not exact (so please don't mark me down -- just warn me or something). I have searched for days for the solution to this SIMPLE issue. Using storyboards, ARC, and Xcode 4.5.2, I simply need to put a bunch of labels inside a UIScrollView and have it scroll vertically. I've tried so many combinations of setting frame sizes and content sizes within viewDidLoad, viewDidAppear, and viewWillAppear, but to no avail. The scroll view scrolls perfectly when there's nothing inside of it, but when I add labels to it, the scrolling only scrolls a very short section.

请注意:我需要使用自动布局,否则我的整个项目将得到搞砸

Note: I need to use auto layout, otherwise my whole project will get messed up.

下面是我目前的code ...

Here's my current code...

.h文件中:

#import <UIKit/UIKit.h>

@interface MortgageRatesViewController : UIViewController <UIScrollViewDelegate, UIScrollViewAccessibilityDelegate>

- (IBAction)backButton:(id)sender;

@property (strong, nonatomic) IBOutlet UIView *mortgageView;

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

@end

.m文件:

#import "MortgageRatesViewController.h"


@interface MortgageRatesViewController ()

@end

@implementation MortgageRatesViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

//-------------------------------------------------------

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"appBackgroundColor.png"]];


    [self.scrollView setScrollEnabled:YES];
    [self.scrollView setContentSize:CGSizeMake(0, 809)];



}

//---------------------------------------------------------------

//---------------------------------------------------------------

//-(void)viewWillAppear:(BOOL)animated{
//    
//    
//    [super viewWillAppear:animated];
//    
//    
//    [self.scrollView setFrame:CGRectMake(0, 0, 320, 808)];   
//
//    
//}

//---------------------------------------------------------------

-(void)viewDidAppear:(BOOL)animated
{

    [super viewDidAppear:animated];

    [self.view addSubview:self.scrollView];
    [self.scrollView setScrollEnabled:YES];
    [self.scrollView setContentSize:CGSizeMake(0, 809)];

}

//-------------------------------------------------------------

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)backButton:(id)sender {

    [self dismissViewControllerAnimated:YES completion:NO];

}
@end

注意:有viewWillAppear中注释掉已经没有什么区别

编辑:我张贴了下面的解决方案。希望它可以帮助别人!

推荐答案

在研究天,这很有趣,我居然找到了解决办法张贴这个问题只有几分钟后!所以,我的情况,我只是不得不加code这一点,和它的工作:

After days of research, it's funny I actually found the solution just minutes after posting this question! So, for my situation I simply had to add this bit of code, and it worked:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [self.scrollView setContentSize:CGSizeMake(320, 808)];
}

这似乎是现在的工作完美。请,任何人,让我知道,如果这是这样做的一个好办法,因为我是新来的这一点,我会爱任何帮助。否则,我会离开它,希望这可以帮助其他人!谢谢!

It seems to be working perfectly now. Please, anyone, let me know if this is a poor way of doing it, because I'm new to this and I would love any help. Otherwise, I'll leave it and hope this can help other people! Thanks!

这篇关于为什么不加入的UIScrollView对象后完全滚动?使用故事板,ARC,和X code 4.5.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆