2015-09-08 98 views
-2

。現在滾動型與我有一個觀點和我有一些標籤是視圖中的滾動視圖標籤

當我安裝我的約束一切正常,除了視圖不會滾動。

這是我的視圖控制器:

#import <Reliant/NSObject+OCSReliantInjection.h> 
#import "GinDetailViewController.h" 
#import "Gin.h" 
#import "View+MASAdditions.h" 
#import "Country.h" 

@interface GinDetailViewController() 
@property(nonatomic, strong) UILabel *titleContents; 
@property(nonatomic, strong) UILabel *detailContents; 

@property(nonatomic, strong) UILabel *titleAlcohol; 
@property(nonatomic, strong) UILabel *detailAlcohol; 

@property(nonatomic, strong) UILabel *titleOrigin; 
@property(nonatomic, strong) UILabel *detailOrigin; 

@property(nonatomic, strong) UILabel *titleType; 
@property(nonatomic, strong) UILabel *detailType; 

@property(nonatomic, strong) UILabel *titleTaste; 
@property(nonatomic, strong) UILabel *detailTaste; 

@property(nonatomic, strong) UIScrollView *scrollView; 
@property(nonatomic, strong) UIView *container; 
@end 

@implementation GinDetailViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self _inject]; 
    [self _initUI]; 
} 

- (void)_inject { 
    [self ocsInject]; 
} 

- (void)_initUI { 
    self.view.backgroundColor = [UIColor whiteColor]; 
    self.navigationItem.title = @"Details"; 
    [self _setupScrollView]; 
    [self _setupView]; 
    [self _setupContents]; 
    [self _setupAlcohol]; 
    [self _setupOrigin]; 
    [self _setupType]; 
    [self _setupTaste]; 
} 

- (void)_setupScrollView { 
    _scrollView = [[UIScrollView alloc] init]; 
    [self.view addSubview:_scrollView]; 

    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.edges.equalTo(self.view); 
    }]; 
} 

- (void)_setupView { 
    _container = [[UIView alloc] init]; 

    [_scrollView addSubview:_container]; 

    [_container mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.width.equalTo(self.view).offset(-8); 
     make.height.equalTo(self.view).offset(-8); 
     make.top.left.equalTo(self.scrollView).offset(8.0); 
    }]; 
} 

- (void)_setupContents { 
    _titleContents = [[UILabel alloc] init]; 
    _titleContents.text = @"Contents"; 
    [self.container addSubview:_titleContents]; 

    [_titleContents mas_makeConstraints:^(MASConstraintMaker *make) { 
     UIView *topLayoutGuide = (id) self.topLayoutGuide; 
     make.top.equalTo(topLayoutGuide.mas_bottom); 
     make.left.equalTo(self.container).offset(8); 
    }]; 

    _detailContents = [[UILabel alloc] init]; 
    _detailContents.text = _gin.contents; 
    [self.container addSubview:_detailContents]; 

    [_detailContents mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.top.equalTo(_titleContents); 
     make.left.equalTo(_titleContents.mas_right).offset(8); 
    }]; 
} 

- (void)_setupAlcohol { 
    _titleAlcohol = [[UILabel alloc] init]; 
    _titleAlcohol.text = @"Alcohol"; 
    [self.container addSubview:_titleAlcohol]; 

    [_titleAlcohol mas_makeConstraints:^(MASConstraintMaker *make) { 
     UIView *topLayoutGuide = (id) self.topLayoutGuide; 
     make.top.equalTo(topLayoutGuide.mas_bottom); 
     make.left.equalTo(self.container.mas_centerX).offset(8); 
    }]; 

    _detailAlcohol = [[UILabel alloc] init]; 
    _detailAlcohol.text = [NSString stringWithFormat:@"%@°", _gin.alcohol]; 
    [self.container addSubview:_detailAlcohol]; 

    [_detailAlcohol mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.top.equalTo(_titleAlcohol); 
     make.left.equalTo(_titleAlcohol.mas_right).offset(8); 
    }]; 
} 

- (void)_setupOrigin { 
    _titleOrigin = [[UILabel alloc] init]; 
    _titleOrigin.text = @"Origin"; 
    [self.container addSubview:_titleOrigin]; 

    [_titleOrigin mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.top.equalTo(_titleContents.mas_bottom).offset(8); 
     make.left.equalTo(_titleContents); 
    }]; 

    _detailOrigin = [[UILabel alloc] init]; 
    NSArray *countries = [_gin.origin allObjects]; 
    if (countries.count > 0) { 
     Country *country = countries[0]; 
     _detailOrigin.text = country.name; 
    } 
    [self.container addSubview:_detailOrigin]; 

    [_detailOrigin mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.top.equalTo(_titleOrigin); 
     make.left.equalTo(_titleOrigin.mas_right).offset(8); 
    }]; 
} 

- (void)_setupType { 
    _titleType = [[UILabel alloc] init]; 
    _titleType.text = @"Type"; 
    [self.container addSubview:_titleType]; 

    [_titleType mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.top.equalTo(_titleAlcohol.mas_bottom).offset(8); 
     make.left.equalTo(self.container.mas_centerX).offset(8); 
    }]; 

    _detailType = [[UILabel alloc] init]; 
    _detailType.text = _gin.type; 
    [self.container addSubview:_detailType]; 

    [_detailType mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.top.equalTo(_titleType); 
     make.left.equalTo(_titleType.mas_right).offset(8); 
    }]; 
} 

- (void)_setupTaste { 
    _titleTaste = [[UILabel alloc] init]; 
    _titleTaste.text = @"Taste"; 
    [self.container addSubview:_titleTaste]; 

    [_titleTaste mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.top.equalTo(_titleOrigin.mas_bottom).offset(16); 
     make.left.equalTo(self.container).offset(8); 
    }]; 

    _detailTaste = [[UILabel alloc] init]; 
    _detailTaste.lineBreakMode = NSLineBreakByWordWrapping; 
    //_detailTaste.text = _gin.taste; 
    _detailTaste.text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi dictum porta mattis. Cras efficitur efficitur orci at ultrices. Integer faucibus fermentum arcu vitae dapibus. Maecenas mollis augue placerat tellus ultrices, auctor congue dolor efficitur. Proin semper velit venenatis justo volutpat, vel fermentum ipsum pellentesque. Integer tempus at ex ut ultrices. Etiam varius tempor eros hendrerit gravida. Nunc placerat felis sit amet magna faucibus molestie. Curabitur iaculis euismod gravida. Maecenas vehicula dolor orci, ac interdum turpis gravida a. Suspendisse eleifend ante vel odio faucibus, non ultrices odio ornare. Etiam interdum justo convallis sem fermentum posuere. Pellentesque ut orci tincidunt, feugiat lectus a, volutpat arcu.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi dictum porta mattis. Cras efficitur efficitur orci at ultrices. Integer faucibus fermentum arcu vitae dapibus. Maecenas mollis augue placerat tellus ultrices, auctor congue dolor efficitur. Proin semper velit venenatis justo volutpat, vel fermentum ipsum pellentesque. Integer tempus at ex ut ultrices. Etiam varius tempor eros hendrerit gravida. Nunc placerat felis sit amet magna faucibus molestie. Curabitur iaculis euismod gravida. Maecenas vehicula dolor orci, ac interdum turpis gravida a. Suspendisse eleifend ante vel odio faucibus, non ultrices odio ornare. Etiam interdum justo convallis sem fermentum posuere. Pellentesque ut orci tincidunt, feugiat lectus a, volutpat arcu.\n" 
      ""; 
    _detailTaste.numberOfLines = 0; 
    [self.container addSubview:_detailTaste]; 

    [_detailTaste mas_makeConstraints:^(MASConstraintMaker *make) { 
     make.top.equalTo(_titleTaste.mas_bottom).offset(8); 
     make.left.equalTo(self.container).offset(8); 
     make.right.equalTo(self.container).offset(-8); 
    }]; 
} 


@end 

任何一個想法,爲什麼這不滾動?

+0

哪裏是'_scrollView.contentSize'?沒有'contentSize'滾動視圖將不會滾動。當它的contentSize是大範圍,然後視 –

+1

只會滾動,所以設置你的contentSize –

+2

這不可能是這個有點意見正在使用的UITableViewController和創造UITableViewCells爲UILabels最好的解決辦法,但我recommentation。我推薦的原因是你不會面對內容大小問題或再次滾動。如果您將UITextField添加到此視圖,則使用tableView會更合理,因爲UITableViewController本身會處理所有的keyboardWillHide/Show操作。食物的思考:) –

回答

2

你不設置_scrollView.contentSize。沒有contentSize滾動視圖不會滾動。它應該大於滾動視圖的bounds

如果你想在一個方向上滾動試試這個

_scrollView.contentSize=CGSizeMake(scrollableWidth,scrollableHeight); 

,置另一方向等於其frame.size.heightframe.size.width不管它是什麼。

+0

我需要填寫一些隨機的高值還是可以計算? – user1007522

+0

Offcours你必須計算它。 –

相關問題