Skip to content

Commit

Permalink
safeAreaLayoutGuide demo
Browse files Browse the repository at this point in the history
  • Loading branch information
iwill committed Sep 27, 2017
1 parent f131c1c commit a2f1d06
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 33 deletions.
10 changes: 6 additions & 4 deletions Examples/Masonry iOS Examples.xcodeproj/project.pbxproj
Expand Up @@ -32,6 +32,7 @@
DD9B4D35183CC980002BF408 /* MASExampleScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD9B4D34183CC980002BF408 /* MASExampleScrollView.m */; };
DDDF60CC181915E300BF7B8B /* MASExampleLabelView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDDF60CB181915E300BF7B8B /* MASExampleLabelView.m */; };
DDF3875C179D648D00178773 /* MASExampleAnimatedView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDF3875B179D648D00178773 /* MASExampleAnimatedView.m */; };
DFBACE591F7B76E40047F15A /* MASExampleSafeAreaLayoutGuideViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DFBACE581F7B76E40047F15A /* MASExampleSafeAreaLayoutGuideViewController.m */; };
DFBACE5D1F7B86860047F15A /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DFBACE5C1F7B86860047F15A /* Launch Screen.storyboard */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -84,6 +85,8 @@
DDDF60CB181915E300BF7B8B /* MASExampleLabelView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleLabelView.m; sourceTree = "<group>"; };
DDF3875A179D648D00178773 /* MASExampleAnimatedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleAnimatedView.h; sourceTree = "<group>"; };
DDF3875B179D648D00178773 /* MASExampleAnimatedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleAnimatedView.m; sourceTree = "<group>"; };
DFBACE571F7B76E30047F15A /* MASExampleSafeAreaLayoutGuideViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASExampleSafeAreaLayoutGuideViewController.h; sourceTree = "<group>"; };
DFBACE581F7B76E40047F15A /* MASExampleSafeAreaLayoutGuideViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASExampleSafeAreaLayoutGuideViewController.m; sourceTree = "<group>"; };
DFBACE5C1F7B86860047F15A /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -200,6 +203,8 @@
DD52F250179CADC0005CD195 /* MASExampleViewController.m */,
DD653E481843E61500D1EC5A /* MASExampleLayoutGuideViewController.h */,
DD653E491843E61500D1EC5A /* MASExampleLayoutGuideViewController.m */,
DFBACE571F7B76E30047F15A /* MASExampleSafeAreaLayoutGuideViewController.h */,
DFBACE581F7B76E40047F15A /* MASExampleSafeAreaLayoutGuideViewController.m */,
);
name = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -344,6 +349,7 @@
27A27D461A6CF0C400D34F52 /* MASExampleAspectFitView.m in Sources */,
DD52F252179CADC0005CD195 /* MASExampleConstantsView.m in Sources */,
DD52F253179CADC0005CD195 /* MASExampleListViewController.m in Sources */,
DFBACE591F7B76E40047F15A /* MASExampleSafeAreaLayoutGuideViewController.m in Sources */,
DD52F254179CADC0005CD195 /* MASExampleSidesView.m in Sources */,
DD32C3FD18E8BFF6001F6AD2 /* MASExampleAttributeChainingView.m in Sources */,
DD52F255179CADC0005CD195 /* MASExampleViewController.m in Sources */,
Expand Down Expand Up @@ -409,7 +415,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -449,7 +454,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -464,7 +468,6 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Masonry iOS Examples/Masonry iOS Examples-Prefix.pch";
INFOPLIST_FILE = "Masonry iOS Examples/Masonry iOS Examples-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.cloudling.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "Masonry iOS Examples";
WRAPPER_EXTENSION = app;
Expand All @@ -478,7 +481,6 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Masonry iOS Examples/Masonry iOS Examples-Prefix.pch";
INFOPLIST_FILE = "Masonry iOS Examples/Masonry iOS Examples-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.cloudling.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "Masonry iOS Examples";
WRAPPER_EXTENSION = app;
Expand Down
21 changes: 12 additions & 9 deletions Examples/Masonry iOS Examples/Launch Screen.storyboard
Expand Up @@ -4,7 +4,6 @@
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -14,37 +13,41 @@
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="cbD-vd-OFn"/>
<viewControllerLayoutGuide type="bottom" id="TBi-GG-GBk"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Copyright © 2017 Jonas Budelmann. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="0.0" y="612.5" width="375" height="20.5"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="47.5" y="592.5" width="281" height="41"/>
<string key="text">Copyright © 2017 Jonas Budelmann.
All rights reserved.</string>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Masonry" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<rect key="frame" x="0.0" y="202" width="375" height="43"/>
<rect key="frame" x="114.5" y="202" width="146" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="SfN-ll-jLj"/>
<constraint firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
<constraint firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
<constraint firstAttribute="bottom" secondItem="obG-Y5-kRd" secondAttribute="bottom" constant="34" id="Y44-ml-fuU"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="x7j-FC-K8j"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
<point key="canvasLocation" x="52" y="374.66266866566718"/>
</scene>
</scenes>
</document>
6 changes: 6 additions & 0 deletions Examples/Masonry iOS Examples/MASExampleListViewController.m
Expand Up @@ -18,6 +18,7 @@
#import "MASExampleRemakeView.h"
#import "MASExampleScrollView.h"
#import "MASExampleLayoutGuideViewController.h"
#import "MASExampleSafeAreaLayoutGuideViewController.h"
#import "MASExampleArrayView.h"
#import "MASExampleAttributeChainingView.h"
#import "MASExampleAspectFitView.h"
Expand Down Expand Up @@ -77,6 +78,11 @@ - (id)init {
self.exampleControllers = [self.exampleControllers arrayByAddingObject:[[MASExampleLayoutGuideViewController alloc] init]];
}

if ([UIView instancesRespondToSelector:@selector(safeAreaLayoutGuide)])
{
self.exampleControllers = [self.exampleControllers arrayByAddingObject:[[MASExampleSafeAreaLayoutGuideViewController alloc] init]];
}

return self;
}

Expand Down
@@ -0,0 +1,13 @@
//
// MASExampleSafeAreaLayoutGuideViewController.h
// Masonry iOS Examples
//
// Created by MingLQ on 2017-09-27.
// Copyright © 2017 MingLQ. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MASExampleSafeAreaLayoutGuideViewController : UIViewController

@end
@@ -0,0 +1,131 @@
//
// MASExampleSafeAreaLayoutGuideViewController.m
// Masonry iOS Examples
//
// Created by MingLQ on 2017-09-27.
// Copyright © 2017 MingLQ. All rights reserved.
//

#import "MASExampleSafeAreaLayoutGuideViewController.h"

@interface MASExampleSafeAreaLayoutGuideViewController ()

@end

@implementation MASExampleSafeAreaLayoutGuideViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"Safe Area Layout Guides";
}
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];

self.view.backgroundColor = [UIColor whiteColor];

UIView *view1 = [UIView new];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];

UIView *view2 = [UIView new];
view2.backgroundColor = [UIColor greenColor];
[self.view addSubview:view2];

UIView *view3 = [UIView new];
view3.backgroundColor = [UIColor blueColor];
[self.view addSubview:view3];

UIView *leftView = [self viewWithName:@"LY"];
UIView *rightView = [self viewWithName:@"RY"];
UIView *topView = [self viewWithName:@"TX"];
UIView *bottomView = [self viewWithName:@"BX"];

UIView *leftTopView = [self viewWithName:@"LT"];
UIView *rightTopView = [self viewWithName:@"RT"];
UIView *leftBottomView = [self viewWithName:@"LB"];
UIView *rightBottomView = [self viewWithName:@"RB"];

UIView *centerView = [self viewWithName:@"XY"];

const CGFloat size = 50.0;

[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view.mas_safeArea).inset(10.0);
}];

[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view.mas_safeArea);
make.width.height.equalTo(self.view.mas_safeArea).sizeOffset(CGSizeMake(- 40.0, - 40.0));
}];

[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view.mas_safeArea);
make.width.equalTo(self.view.mas_safeArea).sizeOffset(CGSizeMake(- 60.0, - 60.0));
make.height.equalTo(self.view.mas_safeArea).sizeOffset(CGSizeMake(- 60.0, - 60.0));
}];

[leftTopView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(self.view.mas_safeArea);
make.width.height.equalTo(@(size));
}];

[rightTopView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view.mas_safeAreaRight);
make.top.equalTo(self.view.mas_safeAreaTop);
make.width.height.equalTo(@(size));
}];

[leftBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.mas_safeAreaLeft);
make.bottom.equalTo(self.view.mas_safeAreaBottom);
make.width.height.equalTo(@(size));
}];

[rightBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.bottom.equalTo(self.view.mas_safeArea);
make.width.height.equalTo(@(size));
}];

[leftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.centerY.equalTo(self.view.mas_safeArea);
make.width.height.equalTo(@(size));
}];

[rightView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view.mas_safeAreaRight);
make.centerY.equalTo(self.view.mas_safeAreaCenterY);
make.width.height.equalTo(@(size));
}];

[topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_safeAreaTop);
make.centerX.equalTo(self.view.mas_safeAreaCenterX);
make.width.height.equalTo(@(size));
}];

[bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.centerX.equalTo(self.view.mas_safeArea);
make.width.height.equalTo(@(size));
}];

[centerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view.mas_safeArea);
make.width.height.equalTo(@(size));
}];
}

- (UIView *)viewWithName:(NSString *)name {
UILabel *label = [UILabel new];
label.text = name;
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor yellowColor];
[self.view addSubview:label];
return label;
}

@end
4 changes: 0 additions & 4 deletions Masonry.xcodeproj/project.pbxproj
Expand Up @@ -386,7 +386,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.9;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -436,7 +435,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.9;
MTL_ENABLE_DEBUG_INFO = NO;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -492,7 +490,6 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Masonry/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.cloudling.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Masonry;
Expand All @@ -511,7 +508,6 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Masonry/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.cloudling.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Masonry;
Expand Down

0 comments on commit a2f1d06

Please sign in to comment.