Created
May 9, 2017 00:19
-
-
Save willard1218/6a47d74c935261e401489a2143aeb52b to your computer and use it in GitHub Desktop.
ScrollView constraint issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// scrollveiwtes | |
// | |
// Created by willard on 2017/5/9. | |
// Copyright © 2017年 willard. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface ViewController () | |
@property (nonatomic, strong) UIScrollView *scrollView; | |
@end | |
@implementation ViewController | |
@synthesize scrollView; | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
scrollView = [[UIScrollView alloc] init]; | |
scrollView.backgroundColor = [UIColor grayColor]; | |
scrollView.translatesAutoresizingMaskIntoConstraints = NO; | |
[self.view addSubview:scrollView]; | |
[scrollView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor constant:20].active = YES; | |
[scrollView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor constant:-20].active = YES; | |
[scrollView.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:20].active = YES; | |
[scrollView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:-20].active = YES; | |
NSLog(@"%@", NSStringFromCGSize(scrollView.contentSize)); | |
UIView *sView = scrollView; | |
UIView *view = [[UIView alloc] init]; | |
view.translatesAutoresizingMaskIntoConstraints = NO; | |
[scrollView addSubview:view]; | |
view.backgroundColor = [UIColor blueColor]; | |
[view.leftAnchor constraintEqualToAnchor:sView.leftAnchor constant:30].active = YES; | |
[view.rightAnchor constraintEqualToAnchor:sView.rightAnchor constant:-30].active = YES; | |
[view.topAnchor constraintEqualToAnchor:sView.topAnchor constant:30].active = YES; | |
[view.bottomAnchor constraintEqualToAnchor:sView.bottomAnchor constant:-30].active = YES; | |
// [view.widthAnchor constraintEqualToConstant:100].active = YES; | |
// [view.heightAnchor constraintEqualToConstant:100].active = YES; | |
} | |
- (void)viewDidAppear:(BOOL)animated { | |
[super viewDidAppear:animated]; | |
//scrollView.contentSize = self.view.frame.size; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment