scrollView高度问题

来源:互联网 发布:河西学院网络选修 编辑:程序博客网 时间:2024/06/07 09:59

1.在viewDidLayoutSubviews里面实现,
两个并行的view(只有一个显示,顶部对齐)适合点

////  ViewController.m//  scrollView////  Copyright © 2016年 ZG. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property(nonatomic,assign) int heightChaZhi;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    [_grayButton addTarget:self action:@selector(grayButtonTap) forControlEvents:UIControlEventTouchUpInside];    [_whiteButton addTarget:self action:@selector(whiteButtonTap) forControlEvents:UIControlEventTouchUpInside];}// 例如:grayView距离下面为a// whiteView下面constant即是  a - (两者的差值);-(void)grayButtonTap{    [_whiteView setHidden:true];    [_grayView setHidden: false];    _whiteBottomConstraint.constant = 10 - _heightChaZhi;}// whiteView距离下面恢复为50-(void)whiteButtonTap{    [_whiteView setHidden:false];    [_grayView setHidden: true];    _whiteBottomConstraint.constant = 50;}// 1.在❣️viewDidLayoutSubviews里面实现,- (void)viewDidLayoutSubviews{    int whiteFrame = _whiteView.frame.size.height;    int grayViewFrame = _grayView.frame.size.height;    _heightChaZhi =(whiteFrame - grayViewFrame);    [self grayButtonTap];}
  • storyBoard布局
  • storyBoard中创建viewcontroller时,scrollview下面,
  • 决定scrollview大小的view,
其有两个子View,其中一个为whiteView,另外一个为grayView,View的高度有值,
  • scrollview才有高度,这里不设死,用whiteView距离View的bottom距离决定View的高度。�� 只设定一个子view(whiteView)的bottom值

这里写图片描述

  • whiteView约束
    这里写图片描述

2.在viewDidLoad中,先按照一个机器,适配,取出总的高度,
然后再各个尺寸高度的真机上面,运行下,看看各个控件的变化
两个上下关系的view适合点

// 2.在viewDidLoad中,先按照一个机器,适配,取出总的高度,然后再各个尺寸高度的真机上面,运行下,看看各个控件的变化//===》两个上下关系的view适合点//    例如://    if () {//  1️⃣ 320宽度上面适配的高度//              authenticationViewHeight.Constant = 829;// 2️⃣ 375宽度上面,一个label上面的4行的字体,72总高的,变成了三行,总高也为72/4 * 3 = 54高度//              if (UIScreen.MainScreen.Bounds.Size.Width == 375) {//        lastLabelHeight.Constant = 54;//        authenticationViewHeight.Constant = 829 - 18;// 3️⃣ 大于375宽度上面,行数变少的有三个地方,这里要减去三个行高。//              } else if (UIScreen.MainScreen.Bounds.Size.Width > 375) {//        lastLabelHeight.Constant = 54;//        contentLabelHeight.Constant = 72;//        pregnetLableHeight.Constant = 16;//        authenticationViewHeight.Constant = 829 - (18 + 18 + 16);//              }//}@end

第二种情况对应:

原创粉丝点击