- Add Icon
- Add LaunchImage - Add Button tu test Token Management and refreshtoken
@ -20,7 +20,6 @@
|
||||
6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
|
||||
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
|
||||
6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
|
||||
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
|
||||
DA43246C4FB8B8B587FC2343 /* Pods_PNObject_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CB6B6AE8DC4C8FBEC56DD55 /* Pods_PNObject_Tests.framework */; };
|
||||
E1806AD43C05C089D52D136E /* Pods_PNObject_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D73089A9DA261B19C7C342EA /* Pods_PNObject_Example.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
@ -60,7 +59,6 @@
|
||||
606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = "<group>"; };
|
||||
6ADA851464A35438E6A21617 /* Pods-PNObject_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNObject_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PNObject_Example/Pods-PNObject_Example.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
75FCB4EFD17838CCA4C93E4A /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
|
||||
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
|
||||
8C017F9292D546DE8DBC84F8 /* PNObject.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = PNObject.podspec; path = ../PNObject.podspec; sourceTree = "<group>"; };
|
||||
9984F97E974B595ED43BA3E3 /* Pods-PNObject_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNObject_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PNObject_Tests/Pods-PNObject_Tests.release.xcconfig"; sourceTree = "<group>"; };
|
||||
BA17B1571B43FAFAA8B45B6D /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
|
||||
@ -134,7 +132,6 @@
|
||||
children = (
|
||||
6003F59C195388D20070C39A /* PNObjectAppDelegate.h */,
|
||||
6003F59D195388D20070C39A /* PNObjectAppDelegate.m */,
|
||||
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */,
|
||||
6003F5A5195388D20070C39A /* PNObjectViewController.h */,
|
||||
6003F5A6195388D20070C39A /* PNObjectViewController.m */,
|
||||
6003F5A8195388D20070C39A /* Images.xcassets */,
|
||||
@ -278,7 +275,6 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */,
|
||||
6003F5A9195388D20070C39A /* Images.xcassets in Resources */,
|
||||
6003F598195388D20070C39A /* InfoPlist.strings in Resources */,
|
||||
);
|
||||
|
||||
@ -1,48 +1,129 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-40.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-40@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-60@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "72x72",
|
||||
"idiom" : "ipad",
|
||||
"size" : "29x29",
|
||||
"filename" : "Icon-72.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "72x72",
|
||||
"idiom" : "ipad",
|
||||
"size" : "29x29",
|
||||
"filename" : "Icon-72@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "40x40",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "40x40",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "76x76",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-76.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"size" : "76x76",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-76@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "50x50",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-Small-50.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "50x50",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-Small-50@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-Small.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-Small@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "57x57",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "57x57",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-Small@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-40@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-60@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-40@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-Small.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-Small@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "120x120",
|
||||
"idiom" : "car",
|
||||
"filename" : "Icon-120.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "83.5x83.5",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Icon-83.5@2x.png",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
|
||||
BIN
Example/PNObject/Images.xcassets/AppIcon.appiconset/Icon-120.png
Normal file
|
After Width: | Height: | Size: 523 B |
BIN
Example/PNObject/Images.xcassets/AppIcon.appiconset/Icon-40.png
Normal file
|
After Width: | Height: | Size: 188 B |
|
After Width: | Height: | Size: 353 B |
|
After Width: | Height: | Size: 523 B |
|
After Width: | Height: | Size: 523 B |
|
After Width: | Height: | Size: 958 B |
BIN
Example/PNObject/Images.xcassets/AppIcon.appiconset/Icon-72.png
Normal file
|
After Width: | Height: | Size: 317 B |
|
After Width: | Height: | Size: 722 B |
BIN
Example/PNObject/Images.xcassets/AppIcon.appiconset/Icon-76.png
Normal file
|
After Width: | Height: | Size: 341 B |
|
After Width: | Height: | Size: 782 B |
|
After Width: | Height: | Size: 899 B |
|
After Width: | Height: | Size: 245 B |
|
After Width: | Height: | Size: 458 B |
|
After Width: | Height: | Size: 170 B |
|
After Width: | Height: | Size: 263 B |
|
After Width: | Height: | Size: 387 B |
BIN
Example/PNObject/Images.xcassets/AppIcon.appiconset/Icon.png
Normal file
|
After Width: | Height: | Size: 261 B |
BIN
Example/PNObject/Images.xcassets/AppIcon.appiconset/Icon@2x.png
Normal file
|
After Width: | Height: | Size: 505 B |
@ -1,46 +1,157 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"orientation" : "portrait",
|
||||
"idiom" : "iphone",
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Default.png",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Default@2x.png",
|
||||
"minimum-system-version" : "7.0",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"orientation" : "portrait",
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "iphone",
|
||||
"subtype" : "retina4",
|
||||
"extent" : "full-screen",
|
||||
"minimum-system-version" : "7.0",
|
||||
"filename" : "Default-568h@2x.png",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "iphone",
|
||||
"subtype" : "retina4",
|
||||
"filename" : "Default-568h@2x.png",
|
||||
"minimum-system-version" : "7.0",
|
||||
"orientation" : "portrait",
|
||||
"idiom" : "ipad",
|
||||
"extent" : "full-screen",
|
||||
"minimum-system-version" : "7.0",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"orientation" : "landscape",
|
||||
"idiom" : "ipad",
|
||||
"extent" : "full-screen",
|
||||
"minimum-system-version" : "7.0",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"orientation" : "portrait",
|
||||
"idiom" : "ipad",
|
||||
"extent" : "full-screen",
|
||||
"minimum-system-version" : "7.0",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"orientation" : "landscape",
|
||||
"idiom" : "ipad",
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Default@2x.png",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"extent" : "to-status-bar",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad.png",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"extent" : "to-status-bar",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad@2x.png",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"extent" : "to-status-bar",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~landscape.png",
|
||||
"orientation" : "landscape",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"extent" : "to-status-bar",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~landscape@2x.png",
|
||||
"orientation" : "landscape",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~nostatusbar.png",
|
||||
"minimum-system-version" : "7.0",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~nostatusbar.png",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~nostatusbar@2x.png",
|
||||
"minimum-system-version" : "7.0",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~nostatusbar@2x.png",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~landscape~nostatusbar.png",
|
||||
"minimum-system-version" : "7.0",
|
||||
"orientation" : "landscape",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~landscape~nostatusbar.png",
|
||||
"orientation" : "landscape",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~landscape~nostatusbar@2x.png",
|
||||
"minimum-system-version" : "7.0",
|
||||
"orientation" : "landscape",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "ipad",
|
||||
"filename" : "Default~ipad~landscape~nostatusbar@2x.png",
|
||||
"orientation" : "landscape",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "iphone",
|
||||
"subtype" : "736h",
|
||||
"filename" : "Default-Portrait-736h@3x.png",
|
||||
"minimum-system-version" : "8.0",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "iphone",
|
||||
"subtype" : "736h",
|
||||
"filename" : "Default-Landscape-736h@3x.png",
|
||||
"minimum-system-version" : "8.0",
|
||||
"orientation" : "landscape",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"extent" : "full-screen",
|
||||
"idiom" : "iphone",
|
||||
"subtype" : "667h",
|
||||
"filename" : "Default-667h@2x.png",
|
||||
"minimum-system-version" : "8.0",
|
||||
"orientation" : "portrait",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
|
||||
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 58 KiB |
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="whP-gf-Uak">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Object View Controller-->
|
||||
<scene sceneID="wQg-tq-qST">
|
||||
<objects>
|
||||
<viewController id="whP-gf-Uak" customClass="PNObjectViewController" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="uEw-UM-LJ8"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="Mvr-aV-6Um"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="TpU-gO-2f1">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="tc2-Qw-aMS" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="305" y="433"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
@ -24,8 +24,25 @@
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
<key>NSExceptionDomains</key>
|
||||
<dict>
|
||||
<key>giuseppenucifora.com</key>
|
||||
<dict>
|
||||
<key>NSIncludesSubdomains</key>
|
||||
<true/>
|
||||
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
|
||||
<true/>
|
||||
<key>NSTemporaryExceptionMinimumTLSVersion</key>
|
||||
<string>TLSv1.1</string>
|
||||
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
@ -37,6 +54,7 @@
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
@ -45,24 +63,5 @@
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
<key>NSExceptionDomains</key>
|
||||
<dict>
|
||||
<key>giuseppenucifora.com</key>
|
||||
<dict>
|
||||
<key>NSIncludesSubdomains</key>
|
||||
<true/>
|
||||
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
|
||||
<true/>
|
||||
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
|
||||
<true/>
|
||||
<key>NSTemporaryExceptionMinimumTLSVersion</key>
|
||||
<string>TLSv1.1</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@ -1,104 +1,54 @@
|
||||
//
|
||||
// PNObjectAppDelegate.m
|
||||
// PNObject
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 12/28/2015.
|
||||
// Copyright (c) 2015 Giuseppe Nucifora. All rights reserved.
|
||||
//
|
||||
//
|
||||
// PNObjectAppDelegate.m
|
||||
// PNObject
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 12/28/2015.
|
||||
// Copyright (c) 2015 Giuseppe Nucifora. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PNObjectAppDelegate.h"
|
||||
#import "PNObjectViewController.h"
|
||||
|
||||
|
||||
|
||||
#import "PNObject.h"
|
||||
#import "PNUser.h"
|
||||
#import "PNAddress.h"
|
||||
#import "PNObject+PNObjectConnection.h"
|
||||
|
||||
|
||||
@implementation PNObjectAppDelegate
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
|
||||
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
// Override point for customization after application launch.
|
||||
|
||||
|
||||
|
||||
|
||||
[PNObjectConfig initSharedInstanceForEnvironments:@{ EnvironmentDevelopment : @"https://development.it/api/v1",
|
||||
EnvironmentStage : @"https://stage.it/api/v1",
|
||||
EnvironmentProduction : @"https://pnobject.giuseppenucifora.com/"
|
||||
} withOauth:NO];
|
||||
|
||||
[[PNObjectConfig sharedInstance] setEnvironment:Production];
|
||||
|
||||
//[[[PNObjectConfig sharedInstance] manager] setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]];
|
||||
//[[PNObjectConfig sharedInstance] manager].securityPolicy.allowInvalidCertificates = YES;
|
||||
|
||||
//[PNObject get];
|
||||
[PNObjectConfig initSharedInstanceForEnvironments:@{EnvironmentDevelopment : @"http://packman.local/app_dev.php/api/v1/",
|
||||
EnvironmentStage : @"https://packman.ppreview.it/app_stage.php/api/v1/",
|
||||
EnvironmentProduction : @"http://packman.ppreview.it/app_stage.php/api/v1/"
|
||||
} withOauth:YES];
|
||||
[[PNObjectConfig sharedInstance] setHTTPHeaderValue:@"application/x-www-form-urlencoded" forKey:@"Content-Type"];
|
||||
[[PNObjectConfig sharedInstance] setClientID:@"1_pqjo2w5k7j4g8skco408oc048w8so0ws840gcg8k8gwsgk0g4" clientSecret:@"10w0vg2v6eggooc4wks4w4s0wkwok0wkck0w888so0o80g88w8" forEnv:Stage];
|
||||
#ifdef DEBUG
|
||||
[[PNObjectConfig sharedInstance] setEnvironment:Stage];
|
||||
#endif
|
||||
|
||||
PNUser *user = [PNUser currentUser];
|
||||
|
||||
//NSLog(@"user : %@",[user getJSONObject]);
|
||||
|
||||
//[user autoRemoveLocally];
|
||||
[user setFirstName:@"Giuseppe2"];
|
||||
[user setLastName:@"Nucifora2"];
|
||||
[user setEmail:@"giuseppe.nucifora@giuseppenucifora.com"];
|
||||
[user setSex:@"M"];
|
||||
[user setHasAcceptedNewsletter:NO];
|
||||
[user setHasAcceptedPrivacy:YES];
|
||||
[user setUsername:@"giuseppe.nucifora"];
|
||||
[user setPassword:@"giuseppe.nucifora.password"];
|
||||
[user setPhone:@"+393485904995"];
|
||||
[user setUserId:@"blablabla"];
|
||||
[user saveLocally];
|
||||
[user setFirstName:@"Giuseppe"];
|
||||
[user setLastName:@"Nuficora"];
|
||||
[user setEmail:@"giuseppe.nucifora@purplenetwork.it"];
|
||||
[user setPassword:@"asdasdasd"];
|
||||
[user setConfirmPassword:@"asdasdasd"];
|
||||
|
||||
|
||||
PNObjectViewController *viewController = [[PNObjectViewController alloc] init];
|
||||
|
||||
[user setFirstName:@"Angela"];
|
||||
[user setLastName:@"Sapienza"];
|
||||
|
||||
[user JSONObject];
|
||||
|
||||
|
||||
/*[[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingString:[PNAccessToken PNObjEndPoint]] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
|
||||
|
||||
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
|
||||
PNAccessToken *accessToken = [[PNAccessToken alloc] initWithJSON:responseObject];
|
||||
|
||||
NSLog(@"%@",[accessToken JSONObject]);
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[accessToken saveLocally];
|
||||
});
|
||||
//[accessToken saveLocally];
|
||||
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
|
||||
NSLog(@"%@",error);
|
||||
|
||||
}];*/
|
||||
|
||||
//NSLog(@"%@",userDictionary);
|
||||
|
||||
/*
|
||||
|
||||
|
||||
PNAddress *address1 = [[PNAddress alloc] init];
|
||||
[address1 setZip:@"95014"];
|
||||
[address1 setCountry:@"Italy"];
|
||||
[address1 setCity:@"Giarre"];
|
||||
[address1 setProvince:@"Catania"];
|
||||
|
||||
NSLog(@"%@",[address1 saveLocally]);
|
||||
|
||||
|
||||
PNAddress *address2 = [[PNAddress alloc] init];
|
||||
[address2 setZip:@"95014"];
|
||||
[address2 setCountry:@"Italy"];
|
||||
[address2 setCity:@"Giarre"];
|
||||
[address2 setProvince:@"Catania"];
|
||||
|
||||
NSLog(@"%@",[address2 saveLocally]);*/
|
||||
_window.rootViewController = viewController;
|
||||
|
||||
_window.backgroundColor = [UIColor whiteColor];
|
||||
[_window makeKeyAndVisible];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@ -7,10 +7,22 @@
|
||||
//
|
||||
|
||||
#import "PNObjectViewController.h"
|
||||
|
||||
#import <PureLayout/PureLayout.h>
|
||||
#import "PNObject.h"
|
||||
#import "PNUser.h"
|
||||
#import "PNAddress.h"
|
||||
#import "PNObject+PNObjectConnection.h"
|
||||
|
||||
@interface PNObjectViewController ()
|
||||
|
||||
@property (nonatomic) BOOL didSetupConstraints;
|
||||
|
||||
@property (nonatomic, strong) UIButton *refreshToken;
|
||||
|
||||
@property (nonatomic, strong) UIButton *apiCall;
|
||||
|
||||
@property (nonatomic, strong) UIButton *cancelToken;
|
||||
|
||||
@end
|
||||
|
||||
@implementation PNObjectViewController
|
||||
@ -18,7 +30,82 @@
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
_refreshToken = [UIButton newAutoLayoutView];
|
||||
[_refreshToken addTarget:self action:@selector(refreshTokenAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_refreshToken setTitle:@"Refresh Token" forState:UIControlStateNormal];
|
||||
[_refreshToken setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
||||
[_refreshToken.layer setBorderColor:[UIColor blackColor].CGColor];
|
||||
[_refreshToken.layer setCornerRadius:4];
|
||||
[_refreshToken.layer setBorderWidth:2];
|
||||
|
||||
[self.view addSubview:_refreshToken];
|
||||
|
||||
_apiCall = [UIButton newAutoLayoutView];
|
||||
[_apiCall addTarget:self action:@selector(apiCallAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_apiCall setTitle:@"API Call" forState:UIControlStateNormal];
|
||||
[_apiCall setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
||||
[_apiCall.layer setBorderColor:[UIColor blackColor].CGColor];
|
||||
[_apiCall.layer setCornerRadius:4];
|
||||
[_apiCall.layer setBorderWidth:2];
|
||||
|
||||
[self.view addSubview:_apiCall];
|
||||
|
||||
_cancelToken = [UIButton newAutoLayoutView];
|
||||
[_cancelToken addTarget:self action:@selector(cancelTokenAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_cancelToken setTitle:@"Reset Token" forState:UIControlStateNormal];
|
||||
[_cancelToken setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
||||
[_cancelToken.layer setBorderColor:[UIColor blackColor].CGColor];
|
||||
[_cancelToken.layer setCornerRadius:4];
|
||||
[_cancelToken.layer setBorderWidth:2];
|
||||
|
||||
[self.view addSubview:_cancelToken];
|
||||
|
||||
[self.view setNeedsUpdateConstraints];
|
||||
}
|
||||
|
||||
- (void) updateViewConstraints {
|
||||
if (!_didSetupConstraints) {
|
||||
|
||||
_didSetupConstraints = YES;
|
||||
|
||||
[self.view autoPinEdgesToSuperviewEdges];
|
||||
|
||||
[_refreshToken autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
[_refreshToken autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
[_refreshToken autoSetDimension:ALDimensionWidth toSize:140];
|
||||
[_refreshToken autoSetDimension:ALDimensionHeight toSize:44];
|
||||
|
||||
[_apiCall autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:_refreshToken withOffset:-35];
|
||||
[_apiCall autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
[_apiCall autoSetDimension:ALDimensionWidth toSize:140];
|
||||
[_apiCall autoSetDimension:ALDimensionHeight toSize:44];
|
||||
|
||||
|
||||
[_cancelToken autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
[_cancelToken autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_refreshToken withOffset:35];
|
||||
[_cancelToken autoSetDimension:ALDimensionWidth toSize:140];
|
||||
[_cancelToken autoSetDimension:ALDimensionHeight toSize:44];
|
||||
|
||||
}
|
||||
[super updateViewConstraints];
|
||||
}
|
||||
|
||||
- (void) refreshTokenAction {
|
||||
[[PNObjectConfig sharedInstance] refreshTokenForClientCredential];
|
||||
}
|
||||
|
||||
- (void) cancelTokenAction {
|
||||
[[PNObjectConfig sharedInstance] resetToken];
|
||||
}
|
||||
|
||||
- (void) apiCallAction {
|
||||
|
||||
[[PNUser currentUser] registerCurrentUserWithBlockSuccess:^(id _Nullable responseObject) {
|
||||
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
|
||||
@ -11,6 +11,7 @@ target 'PNObject_Example' do
|
||||
pod 'NSString-Helper'
|
||||
pod 'CodFis-Helper'
|
||||
pod 'StrongestPasswordValidator'
|
||||
pod 'PureLayout'
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ PODS:
|
||||
- PEAR-FileManager-iOS
|
||||
- StrongestPasswordValidator
|
||||
- UIDevice-Utils
|
||||
- PureLayout (3.0.1)
|
||||
- Specta (1.0.5)
|
||||
- StrongestPasswordValidator (0.1.1)
|
||||
- UIDevice-Utils (0.1.4)
|
||||
@ -52,6 +53,7 @@ DEPENDENCIES:
|
||||
- nv-ios-http-status
|
||||
- PEAR-FileManager-iOS
|
||||
- PNObject (from `../`)
|
||||
- PureLayout
|
||||
- Specta
|
||||
- StrongestPasswordValidator
|
||||
- UIDevice-Utils
|
||||
@ -71,10 +73,11 @@ SPEC CHECKSUMS:
|
||||
nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f
|
||||
PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3
|
||||
PNObject: f1a1126226e7f0dac81111a98e49b8653603f518
|
||||
PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb
|
||||
Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2
|
||||
StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b
|
||||
UIDevice-Utils: 0beb5f9d2bd256a3efe05c1e43a2a8b8702199c4
|
||||
|
||||
PODFILE CHECKSUM: 99adfd0e15d4fe00ec0e738a05da2a580764ba73
|
||||
PODFILE CHECKSUM: 17e9b803760ee3243260eb8a4dbc6fd15054c221
|
||||
|
||||
COCOAPODS: 1.0.0.beta.3
|
||||
|
||||
@ -196,7 +196,6 @@
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
__block NSURLSessionDataTask *task = [self uploadTaskWithStreamedRequest:request progress:uploadProgress completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
|
||||
if (error) {
|
||||
if (failure) {
|
||||
|
||||
5
Example/Pods/Manifest.lock
generated
@ -37,6 +37,7 @@ PODS:
|
||||
- PEAR-FileManager-iOS
|
||||
- StrongestPasswordValidator
|
||||
- UIDevice-Utils
|
||||
- PureLayout (3.0.1)
|
||||
- Specta (1.0.5)
|
||||
- StrongestPasswordValidator (0.1.1)
|
||||
- UIDevice-Utils (0.1.4)
|
||||
@ -52,6 +53,7 @@ DEPENDENCIES:
|
||||
- nv-ios-http-status
|
||||
- PEAR-FileManager-iOS
|
||||
- PNObject (from `../`)
|
||||
- PureLayout
|
||||
- Specta
|
||||
- StrongestPasswordValidator
|
||||
- UIDevice-Utils
|
||||
@ -71,10 +73,11 @@ SPEC CHECKSUMS:
|
||||
nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f
|
||||
PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3
|
||||
PNObject: f1a1126226e7f0dac81111a98e49b8653603f518
|
||||
PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb
|
||||
Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2
|
||||
StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b
|
||||
UIDevice-Utils: 0beb5f9d2bd256a3efe05c1e43a2a8b8702199c4
|
||||
|
||||
PODFILE CHECKSUM: 99adfd0e15d4fe00ec0e738a05da2a580764ba73
|
||||
PODFILE CHECKSUM: 17e9b803760ee3243260eb8a4dbc6fd15054c221
|
||||
|
||||
COCOAPODS: 1.0.0.beta.3
|
||||
|
||||
2507
Example/Pods/Pods.xcodeproj/project.pbxproj
generated
9
Example/Pods/PureLayout/LICENSE
generated
Executable file
@ -0,0 +1,9 @@
|
||||
This code is distributed under the terms and conditions of the MIT license.
|
||||
|
||||
Copyright (c) 2014-2015 Tyler Fox
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
213
Example/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.h
generated
Executable file
@ -0,0 +1,213 @@
|
||||
//
|
||||
// ALView+PureLayout.h
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
__PL_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark ALView+PureLayout
|
||||
|
||||
/**
|
||||
A category on UIView/NSView that provides a simple yet powerful interface for creating Auto Layout constraints.
|
||||
*/
|
||||
@interface ALView (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Factory & Initializer Methods
|
||||
|
||||
/** Creates and returns a new view that does not convert the autoresizing mask into constraints. */
|
||||
+ (instancetype)newAutoLayoutView;
|
||||
|
||||
/** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */
|
||||
- (instancetype)initForAutoLayout;
|
||||
|
||||
/** Configures an existing view to not convert the autoresizing mask into constraints and returns the view. */
|
||||
- (instancetype)configureForAutoLayout;
|
||||
|
||||
|
||||
#pragma mark Center & Align in Superview
|
||||
|
||||
/** Centers the view in its superview. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview;
|
||||
|
||||
/** Aligns the view to the same axis of its superview. */
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Centers the view in its superview's margins. Available in iOS 8.0 and later. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins;
|
||||
|
||||
/** Aligns the view to the corresponding margin axis of its superview. Available in iOS 8.0 and later. */
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges to Superview
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge;
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview with an inset. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges;
|
||||
|
||||
/** Pins the edges of the view to the edges of its superview with the given edge insets. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets;
|
||||
|
||||
/** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Pins the given edge of the view to the corresponding margin of its superview. Available in iOS 8.0 and later. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge;
|
||||
|
||||
/** Pins the given edge of the view to the corresponding margin of its superview as a maximum or minimum. Available in iOS 8.0 and later. */
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the edges of the view to the margins of its superview. Available in iOS 8.0 and later. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins;
|
||||
|
||||
/** Pins 3 of the 4 edges of the view to the margins of its superview excluding one edge. Available in iOS 8.0 and later. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView;
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Align Axes
|
||||
|
||||
/** Aligns an axis of the view to the same axis of another view. */
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView;
|
||||
|
||||
/** Aligns an axis of the view to the same axis of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Aligns an axis of the view to the same axis of another view with a multiplier. */
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier;
|
||||
|
||||
|
||||
#pragma mark Match Dimensions
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView;
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Matches a dimension of the view to a multiple of a given dimension of another view. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier;
|
||||
|
||||
/** Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Set Dimensions
|
||||
|
||||
/** Sets the view to a specific size. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size;
|
||||
|
||||
/** Sets the given dimension of the view to a specific size. */
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
|
||||
/** Sets the given dimension of the view to a specific size as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Set Content Compression Resistance & Hugging
|
||||
|
||||
/** Sets the priority of content compression resistance for an axis.
|
||||
NOTE: This method must be called from within the block passed into the method +[NSLayoutConstraint autoSetPriority:forConstraints:] */
|
||||
- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis;
|
||||
|
||||
/** Sets the priority of content hugging for an axis.
|
||||
NOTE: This method must be called from within the block passed into the method +[NSLayoutConstraint autoSetPriority:forConstraints:] */
|
||||
- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis;
|
||||
|
||||
|
||||
#pragma mark Constrain Any Attributes
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView;
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view with an offset. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset;
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view with an offset as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view with a multiplier. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier;
|
||||
|
||||
/** Constrains an attribute of the view to a given attribute of another view with a multiplier as a maximum or minimum. */
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
|
||||
|
||||
|
||||
#pragma mark Pin to Layout Guides (iOS only)
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
/** Pins the top edge of the view to the top layout guide of the given view controller with an inset. Available on iOS only. */
|
||||
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the top edge of the view to the top layout guide of the given view controller with an inset as a maximum or minimum. Available on iOS only. */
|
||||
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. Available on iOS only. */
|
||||
- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset;
|
||||
|
||||
/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset as a maximum or minimum. Available on iOS only. */
|
||||
- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
|
||||
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
848
Example/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.m
generated
Executable file
@ -0,0 +1,848 @@
|
||||
//
|
||||
// ALView+PureLayout.m
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
#import "NSArray+PureLayout.h"
|
||||
#import "PureLayout+Internal.h"
|
||||
|
||||
|
||||
#pragma mark - ALView+PureLayout
|
||||
|
||||
@implementation ALView (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Factory & Initializer Methods
|
||||
|
||||
/**
|
||||
Creates and returns a new view that does not convert the autoresizing mask into constraints.
|
||||
*/
|
||||
+ (instancetype)newAutoLayoutView
|
||||
{
|
||||
ALView *view = [self new];
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes and returns a new view that does not convert the autoresizing mask into constraints.
|
||||
*/
|
||||
- (instancetype)initForAutoLayout
|
||||
{
|
||||
self = [self init];
|
||||
if (self) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
Configures an existing view to not convert the autoresizing mask into constraints and returns the view.
|
||||
*/
|
||||
- (instancetype)configureForAutoLayout
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Center in Superview
|
||||
|
||||
/**
|
||||
Centers the view in its superview.
|
||||
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]];
|
||||
[constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Aligns the view to the same axis of its superview.
|
||||
|
||||
@param axis The axis of this view and of its superview to align.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALView *superview = self.superview;
|
||||
NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
|
||||
return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:superview];
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/**
|
||||
Centers the view in its superview, taking into account the layout margins of both the view and its superview.
|
||||
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal]];
|
||||
[constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Aligns the view to the corresponding margin axis of its superview.
|
||||
|
||||
@param axis The axis of this view to align to the corresponding margin axis of its superview.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALView *superview = self.superview;
|
||||
NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
|
||||
ALMarginAxis marginAxis = [NSLayoutConstraint al_marginAxisForAxis:axis];
|
||||
return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)marginAxis ofView:superview];
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges to Superview
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the same edge of its superview.
|
||||
|
||||
@param edge The edge of this view and its superview to pin.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge
|
||||
{
|
||||
return [self autoPinEdgeToSuperviewEdge:edge withInset:0.0];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the same edge of its superview with an inset.
|
||||
|
||||
@param edge The edge of this view and its superview to pin.
|
||||
@param inset The amount to inset this view's edge from the superview's edge.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset
|
||||
{
|
||||
return [self autoPinEdgeToSuperviewEdge:edge withInset:inset relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum.
|
||||
|
||||
@param edge The edge of this view and its superview to pin.
|
||||
@param inset The amount to inset this view's edge from the superview's edge.
|
||||
@param relation Whether the inset should be at least, at most, or exactly equal to the given value.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALView *superview = self.superview;
|
||||
NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
|
||||
if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) {
|
||||
// The bottom, right, and trailing insets (and relations, if an inequality) are inverted to become offsets
|
||||
inset = -inset;
|
||||
if (relation == NSLayoutRelationLessThanOrEqual) {
|
||||
relation = NSLayoutRelationGreaterThanOrEqual;
|
||||
} else if (relation == NSLayoutRelationGreaterThanOrEqual) {
|
||||
relation = NSLayoutRelationLessThanOrEqual;
|
||||
}
|
||||
}
|
||||
return [self autoPinEdge:edge toEdge:edge ofView:superview withOffset:inset relation:relation];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the edges of the view to the edges of its superview.
|
||||
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges
|
||||
{
|
||||
return [self autoPinEdgesToSuperviewEdgesWithInsets:ALEdgeInsetsZero];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the edges of the view to the edges of its superview with the given edge insets.
|
||||
The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
|
||||
|
||||
@param insets The insets for this view's edges from its superview's edges.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge.
|
||||
The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
|
||||
|
||||
@param insets The insets for this view's edges from its superview's edges. The inset corresponding to the excluded edge
|
||||
will be ignored.
|
||||
@param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
if (edge != ALEdgeTop) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
}
|
||||
if (edge != ALEdgeLeading && edge != ALEdgeLeft) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
|
||||
}
|
||||
if (edge != ALEdgeBottom) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
|
||||
}
|
||||
if (edge != ALEdgeTrailing && edge != ALEdgeRight) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]];
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the corresponding margin of its superview.
|
||||
|
||||
@param edge The edge of this view to pin to the corresponding margin of its superview.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge
|
||||
{
|
||||
return [self autoPinEdgeToSuperviewMargin:edge relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the given edge of the view to the corresponding margin of its superview as a maximum or minimum.
|
||||
|
||||
@param edge The edge of this view to pin to the corresponding margin of its superview.
|
||||
@param relation Whether the edge should be inset by at least, at most, or exactly the superview's margin.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALView *superview = self.superview;
|
||||
NSAssert(superview, @"View's superview must not be nil.\nView: %@", self);
|
||||
if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) {
|
||||
// The bottom, right, and trailing relations are inverted
|
||||
if (relation == NSLayoutRelationLessThanOrEqual) {
|
||||
relation = NSLayoutRelationGreaterThanOrEqual;
|
||||
} else if (relation == NSLayoutRelationGreaterThanOrEqual) {
|
||||
relation = NSLayoutRelationLessThanOrEqual;
|
||||
}
|
||||
}
|
||||
ALMargin margin = [NSLayoutConstraint al_marginForEdge:edge];
|
||||
return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)margin ofView:superview withOffset:0.0 relation:relation];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the edges of the view to the margins of its superview.
|
||||
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Pins 3 of the 4 edges of the view to the margins of its superview, excluding one edge.
|
||||
|
||||
@param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
if (edge != ALEdgeTop) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
|
||||
}
|
||||
if (edge != ALEdgeLeading && edge != ALEdgeLeft) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]];
|
||||
}
|
||||
if (edge != ALEdgeBottom) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
|
||||
}
|
||||
if (edge != ALEdgeTrailing && edge != ALEdgeRight) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]];
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
|
||||
#pragma mark Pin Edges
|
||||
|
||||
/**
|
||||
Pins an edge of the view to a given edge of another view.
|
||||
|
||||
@param edge The edge of this view to pin.
|
||||
@param toEdge The edge of the other view to pin to.
|
||||
@param otherView The other view to pin to. Must be in the same view hierarchy as this view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView
|
||||
{
|
||||
return [self autoPinEdge:edge toEdge:toEdge ofView:otherView withOffset:0.0];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins an edge of the view to a given edge of another view with an offset.
|
||||
|
||||
@param edge The edge of this view to pin.
|
||||
@param toEdge The edge of the other view to pin to.
|
||||
@param otherView The other view to pin to. Must be in the same view hierarchy as this view.
|
||||
@param offset The offset between the edge of this view and the edge of the other view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset
|
||||
{
|
||||
return [self autoPinEdge:edge toEdge:toEdge ofView:otherView withOffset:offset relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum.
|
||||
|
||||
@param edge The edge of this view to pin.
|
||||
@param toEdge The edge of the other view to pin to.
|
||||
@param otherView The other view to pin to. Must be in the same view hierarchy as this view.
|
||||
@param offset The offset between the edge of this view and the edge of the other view.
|
||||
@param relation Whether the offset should be at least, at most, or exactly equal to the given value.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
|
||||
{
|
||||
return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)toEdge ofView:otherView withOffset:offset relation:relation];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Align Axes
|
||||
|
||||
/**
|
||||
Aligns an axis of the view to the same axis of another view.
|
||||
|
||||
@param axis The axis of this view and the other view to align.
|
||||
@param otherView The other view to align to. Must be in the same view hierarchy as this view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView
|
||||
{
|
||||
return [self autoAlignAxis:axis toSameAxisOfView:otherView withOffset:0.0];
|
||||
}
|
||||
|
||||
/**
|
||||
Aligns an axis of the view to the same axis of another view with an offset.
|
||||
|
||||
@param axis The axis of this view and the other view to align.
|
||||
@param otherView The other view to align to. Must be in the same view hierarchy as this view.
|
||||
@param offset The offset between the axis of this view and the axis of the other view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset
|
||||
{
|
||||
return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withOffset:offset];
|
||||
}
|
||||
|
||||
/**
|
||||
Aligns an axis of the view to the same axis of another view with a multiplier.
|
||||
|
||||
@param axis The axis of this view and the other view to align.
|
||||
@param otherView The other view to align to. Must be in the same view hierarchy as this view.
|
||||
@param multiplier The multiplier between the axis of this view and the axis of the other view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier
|
||||
{
|
||||
return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withMultiplier:multiplier];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Match Dimensions
|
||||
|
||||
/**
|
||||
Matches a dimension of the view to a given dimension of another view.
|
||||
|
||||
@param dimension The dimension of this view to pin.
|
||||
@param toDimension The dimension of the other view to pin to.
|
||||
@param otherView The other view to match to. Must be in the same view hierarchy as this view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView
|
||||
{
|
||||
return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withOffset:0.0];
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a dimension of the view to a given dimension of another view with an offset.
|
||||
|
||||
@param dimension The dimension of this view to pin.
|
||||
@param toDimension The dimension of the other view to pin to.
|
||||
@param otherView The other view to match to. Must be in the same view hierarchy as this view.
|
||||
@param offset The offset between the dimension of this view and the dimension of the other view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset
|
||||
{
|
||||
return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withOffset:offset relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum.
|
||||
|
||||
@param dimension The dimension of this view to pin.
|
||||
@param toDimension The dimension of the other view to pin to.
|
||||
@param otherView The other view to match to. Must be in the same view hierarchy as this view.
|
||||
@param offset The offset between the dimension of this view and the dimension of the other view.
|
||||
@param relation Whether the offset should be at least, at most, or exactly equal to the given value.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
|
||||
{
|
||||
return [self autoConstrainAttribute:(ALAttribute)dimension toAttribute:(ALAttribute)toDimension ofView:otherView withOffset:offset relation:relation];
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a dimension of the view to a multiple of a given dimension of another view.
|
||||
|
||||
@param dimension The dimension of this view to pin.
|
||||
@param toDimension The dimension of the other view to pin to.
|
||||
@param otherView The other view to match to. Must be in the same view hierarchy as this view.
|
||||
@param multiplier The multiple of the other view's given dimension that this view's given dimension should be.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier
|
||||
{
|
||||
return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withMultiplier:multiplier relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum.
|
||||
|
||||
@param dimension The dimension of this view to pin.
|
||||
@param toDimension The dimension of the other view to pin to.
|
||||
@param otherView The other view to match to. Must be in the same view hierarchy as this view.
|
||||
@param multiplier The multiple of the other view's given dimension that this view's given dimension should be.
|
||||
@param relation Whether the multiple should be at least, at most, or exactly equal to the given value.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation
|
||||
{
|
||||
return [self autoConstrainAttribute:(ALAttribute)dimension toAttribute:(ALAttribute)toDimension ofView:otherView withMultiplier:multiplier relation:relation];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Set Dimensions
|
||||
|
||||
/**
|
||||
Sets the view to a specific size.
|
||||
|
||||
@param size The size to set this view's dimensions to.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObject:[self autoSetDimension:ALDimensionWidth toSize:size.width]];
|
||||
[constraints addObject:[self autoSetDimension:ALDimensionHeight toSize:size.height]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the given dimension of the view to a specific size.
|
||||
|
||||
@param dimension The dimension of this view to set.
|
||||
@param size The size to set the given dimension to.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size
|
||||
{
|
||||
return [self autoSetDimension:dimension toSize:size relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the given dimension of the view to a specific size as a maximum or minimum.
|
||||
|
||||
@param dimension The dimension of this view to set.
|
||||
@param size The size to set the given dimension to.
|
||||
@param relation Whether the size should be at least, at most, or exactly equal to the given value.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:(ALAttribute)dimension];
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:size];
|
||||
[constraint autoInstall];
|
||||
return constraint;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Set Content Compression Resistance & Hugging
|
||||
|
||||
/**
|
||||
Sets the priority of content compression resistance for an axis.
|
||||
NOTE: This method must be called from within the block passed into the method +[autoSetPriority:forConstraints:]
|
||||
|
||||
@param axis The axis to set the content compression resistance priority for.
|
||||
*/
|
||||
- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
|
||||
if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis];
|
||||
#if TARGET_OS_IPHONE
|
||||
[self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis];
|
||||
#else
|
||||
[self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the priority of content hugging for an axis.
|
||||
NOTE: This method must be called from within the block passed into the method +[autoSetPriority:forConstraints:]
|
||||
|
||||
@param axis The axis to set the content hugging priority for.
|
||||
*/
|
||||
- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
|
||||
if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis];
|
||||
#if TARGET_OS_IPHONE
|
||||
[self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis];
|
||||
#else
|
||||
[self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Constrain Any Attributes
|
||||
|
||||
/**
|
||||
Constrains an attribute of the view to a given attribute of another view.
|
||||
This method can be used to constrain different types of attributes across two views.
|
||||
|
||||
@param attribute Any attribute of this view to constrain.
|
||||
@param toAttribute Any attribute of the other view to constrain to.
|
||||
@param otherView The other view to constrain to. Must be in the same view hierarchy as this view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView
|
||||
{
|
||||
return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withOffset:0.0];
|
||||
}
|
||||
|
||||
/**
|
||||
Constrains an attribute of the view to a given attribute of another view with an offset.
|
||||
This method can be used to constrain different types of attributes across two views.
|
||||
|
||||
@param attribute Any attribute of this view to constrain.
|
||||
@param toAttribute Any attribute of the other view to constrain to.
|
||||
@param otherView The other view to constrain to. Must be in the same view hierarchy as this view.
|
||||
@param offset The offset between the attribute of this view and the attribute of the other view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset
|
||||
{
|
||||
return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withOffset:offset relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Constrains an attribute of the view to a given attribute of another view with an offset as a maximum or minimum.
|
||||
This method can be used to constrain different types of attributes across two views.
|
||||
|
||||
@param attribute Any attribute of this view to constrain.
|
||||
@param toAttribute Any attribute of the other view to constrain to.
|
||||
@param otherView The other view to constrain to. Must be in the same view hierarchy as this view.
|
||||
@param offset The offset between the attribute of this view and the attribute of the other view.
|
||||
@param relation Whether the offset should be at least, at most, or exactly equal to the given value.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:attribute];
|
||||
NSLayoutAttribute toLayoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:toAttribute];
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:otherView attribute:toLayoutAttribute multiplier:1.0 constant:offset];
|
||||
[constraint autoInstall];
|
||||
return constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
Constrains an attribute of the view to a given attribute of another view with a multiplier.
|
||||
This method can be used to constrain different types of attributes across two views.
|
||||
|
||||
@param attribute Any attribute of this view to constrain.
|
||||
@param toAttribute Any attribute of the other view to constrain to.
|
||||
@param otherView The other view to constrain to. Must be in the same view hierarchy as this view.
|
||||
@param multiplier The multiplier between the attribute of this view and the attribute of the other view.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier
|
||||
{
|
||||
return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withMultiplier:multiplier relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
/**
|
||||
Constrains an attribute of the view to a given attribute of another view with a multiplier as a maximum or minimum.
|
||||
This method can be used to constrain different types of attributes across two views.
|
||||
|
||||
@param attribute Any attribute of this view to constrain.
|
||||
@param toAttribute Any attribute of the other view to constrain to.
|
||||
@param otherView The other view to constrain to. Must be in the same view hierarchy as this view.
|
||||
@param multiplier The multiplier between the attribute of this view and the attribute of the other view.
|
||||
@param relation Whether the multiplier should be at least, at most, or exactly equal to the given value.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation
|
||||
{
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:attribute];
|
||||
NSLayoutAttribute toLayoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:toAttribute];
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:otherView attribute:toLayoutAttribute multiplier:multiplier constant:0.0];
|
||||
[constraint autoInstall];
|
||||
return constraint;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Pin to Layout Guides
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
/**
|
||||
Pins the top edge of the view to the top layout guide of the given view controller with an inset.
|
||||
For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the top edge of
|
||||
the view to the top edge of the given view controller's view with an inset.
|
||||
|
||||
@param viewController The view controller whose topLayoutGuide should be used to pin to.
|
||||
@param inset The amount to inset this view's top edge from the layout guide.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset
|
||||
{
|
||||
return [self autoPinToTopLayoutGuideOfViewController:viewController withInset:inset relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
|
||||
{
|
||||
if (__PureLayout_MinSysVer_iOS_7_0) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:relation toItem:viewController.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:inset];
|
||||
[viewController.view al_addConstraint:constraint]; // Can't use autoInstall because the layout guide is not a view
|
||||
return constraint;
|
||||
} else {
|
||||
// iOS 6 fallback
|
||||
return [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:viewController.view withOffset:inset relation:relation];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset.
|
||||
For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the bottom edge of
|
||||
the view to the bottom edge of the given view controller's view with an inset.
|
||||
|
||||
@param viewController The view controller whose bottomLayoutGuide should be used to pin to.
|
||||
@param inset The amount to inset this view's bottom edge from the layout guide.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset
|
||||
{
|
||||
return [self autoPinToBottomLayoutGuideOfViewController:viewController withInset:inset relation:NSLayoutRelationEqual];
|
||||
}
|
||||
|
||||
- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation
|
||||
{
|
||||
// The bottom inset (and relation, if an inequality) is inverted to become an offset
|
||||
inset = -inset;
|
||||
if (relation == NSLayoutRelationLessThanOrEqual) {
|
||||
relation = NSLayoutRelationGreaterThanOrEqual;
|
||||
} else if (relation == NSLayoutRelationGreaterThanOrEqual) {
|
||||
relation = NSLayoutRelationLessThanOrEqual;
|
||||
}
|
||||
if (__PureLayout_MinSysVer_iOS_7_0) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:relation toItem:viewController.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:inset];
|
||||
[viewController.view al_addConstraint:constraint]; // Can't use autoInstall because the layout guide is not a view
|
||||
return constraint;
|
||||
} else {
|
||||
// iOS 6 fallback
|
||||
return [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:viewController.view withOffset:inset relation:relation];
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
|
||||
#pragma mark Internal Methods
|
||||
|
||||
/**
|
||||
Adds the given constraint to this view after applying the global state to the constraint.
|
||||
NOTE: This method is compatible with all versions of iOS, and should be used for older versions before the active
|
||||
property on NSLayoutConstraint was introduced.
|
||||
|
||||
This method should be the only one that calls the UIView/NSView addConstraint: method directly.
|
||||
|
||||
@param constraint The constraint to set the global priority on and then add to this view.
|
||||
*/
|
||||
- (void)al_addConstraint:(NSLayoutConstraint *)constraint
|
||||
{
|
||||
[NSLayoutConstraint al_applyGlobalStateToConstraint:constraint];
|
||||
if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
|
||||
[[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:constraint];
|
||||
} else {
|
||||
[self addConstraint:constraint];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the common superview for this view and the given other view.
|
||||
Raises an exception if this view and the other view do not share a common superview.
|
||||
|
||||
@return The common superview for the two views.
|
||||
*/
|
||||
- (ALView *)al_commonSuperviewWithView:(ALView *)otherView
|
||||
{
|
||||
ALView *commonSuperview = nil;
|
||||
ALView *startView = self;
|
||||
do {
|
||||
#if TARGET_OS_IPHONE
|
||||
if ([otherView isDescendantOfView:startView]) {
|
||||
commonSuperview = startView;
|
||||
}
|
||||
#else
|
||||
if ([otherView isDescendantOf:startView]) {
|
||||
commonSuperview = startView;
|
||||
}
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
startView = startView.superview;
|
||||
} while (startView && !commonSuperview);
|
||||
NSAssert(commonSuperview, @"Can't constrain two views that do not share a common superview. Make sure that both views have been added into the same view hierarchy.");
|
||||
return commonSuperview;
|
||||
}
|
||||
|
||||
/**
|
||||
Aligns this view to another view with an alignment attribute.
|
||||
|
||||
@param attribute The attribute to use to align the two views.
|
||||
@param otherView The other view to align to.
|
||||
@param axis The axis along which the views are distributed, used to validate the alignment attribute.
|
||||
@return The constraint added.
|
||||
*/
|
||||
- (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis
|
||||
{
|
||||
NSLayoutConstraint *constraint = nil;
|
||||
switch (attribute) {
|
||||
case ALAttributeVertical:
|
||||
NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeVertical.");
|
||||
constraint = [self autoAlignAxis:ALAxisVertical toSameAxisOfView:otherView];
|
||||
break;
|
||||
case ALAttributeHorizontal:
|
||||
NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeHorizontal.");
|
||||
constraint = [self autoAlignAxis:ALAxisHorizontal toSameAxisOfView:otherView];
|
||||
break;
|
||||
case ALAttributeBaseline: // same value as ALAttributeLastBaseline
|
||||
NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBaseline.");
|
||||
constraint = [self autoAlignAxis:ALAxisBaseline toSameAxisOfView:otherView];
|
||||
break;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAttributeFirstBaseline:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAttributeFirstBaseline is only supported on iOS 8.0 or higher.");
|
||||
NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeFirstBaseline.");
|
||||
constraint = [self autoAlignAxis:ALAxisFirstBaseline toSameAxisOfView:otherView];
|
||||
break;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
case ALAttributeTop:
|
||||
NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeTop.");
|
||||
constraint = [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:otherView];
|
||||
break;
|
||||
case ALAttributeLeft:
|
||||
NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeLeft.");
|
||||
constraint = [self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:otherView];
|
||||
break;
|
||||
case ALAttributeBottom:
|
||||
NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBottom.");
|
||||
constraint = [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:otherView];
|
||||
break;
|
||||
case ALAttributeRight:
|
||||
NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeRight.");
|
||||
constraint = [self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:otherView];
|
||||
break;
|
||||
case ALAttributeLeading:
|
||||
NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeLeading.");
|
||||
constraint = [self autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:otherView];
|
||||
break;
|
||||
case ALAttributeTrailing:
|
||||
NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeTrailing.");
|
||||
constraint = [self autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:otherView];
|
||||
break;
|
||||
|
||||
// All of the below attributes are invalid as alignment options. Listing them explicitly (even though they just fall through to the default case) to avoid an incomplete switch statement warning from the compiler.
|
||||
case ALAttributeWidth:
|
||||
case ALAttributeHeight:
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAttributeMarginLeft:
|
||||
case ALAttributeMarginRight:
|
||||
case ALAttributeMarginTop:
|
||||
case ALAttributeMarginBottom:
|
||||
case ALAttributeMarginLeading:
|
||||
case ALAttributeMarginTrailing:
|
||||
case ALAttributeMarginAxisVertical:
|
||||
case ALAttributeMarginAxisHorizontal:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
default:
|
||||
NSAssert(nil, @"Unsupported attribute for alignment.");
|
||||
break;
|
||||
}
|
||||
return constraint;
|
||||
}
|
||||
|
||||
@end
|
||||
115
Example/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h
generated
Executable file
@ -0,0 +1,115 @@
|
||||
//
|
||||
// NSArray+PureLayout.h
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
__PL_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark NSArray+PureLayout
|
||||
|
||||
/**
|
||||
A category on NSArray that provides a simple yet powerful interface to:
|
||||
- Manage an array of Auto Layout constraints
|
||||
- Apply constraints to an array of views
|
||||
*/
|
||||
@interface NSArray (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Array of Constraints
|
||||
|
||||
/** Activates the constraints in this array. */
|
||||
- (void)autoInstallConstraints;
|
||||
|
||||
/** Deactivates the constraints in this array. */
|
||||
- (void)autoRemoveConstraints;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */
|
||||
- (instancetype)autoIdentifyConstraints:(NSString *)identifier;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Array of Views
|
||||
|
||||
/** Aligns views in this array to one another along a given edge. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge;
|
||||
|
||||
/** Aligns views in this array to one another along a given axis. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis;
|
||||
|
||||
/** Matches a given dimension of all the views in this array. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension;
|
||||
|
||||
/** Sets the given dimension of all the views in this array to a given size. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
|
||||
/** Sets all of the views in this array to a given size. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size;
|
||||
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
matchedSizes:(BOOL)shouldMatchSizes;
|
||||
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size;
|
||||
|
||||
/** Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
insetSpacing:(BOOL)shouldSpaceInsets;
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
505
Example/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.m
generated
Executable file
@ -0,0 +1,505 @@
|
||||
//
|
||||
// NSArray+PureLayout.m
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "NSArray+PureLayout.h"
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
#import "PureLayout+Internal.h"
|
||||
|
||||
|
||||
#pragma mark - NSArray+PureLayout
|
||||
|
||||
@implementation NSArray (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Array of Constraints
|
||||
|
||||
/**
|
||||
Activates the constraints in this array.
|
||||
*/
|
||||
- (void)autoInstallConstraints
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) {
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[NSLayoutConstraint al_applyGlobalStateToConstraint:object];
|
||||
}
|
||||
}
|
||||
if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
|
||||
[[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObjectsFromArray:self];
|
||||
} else {
|
||||
[NSLayoutConstraint activateConstraints:self];
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[((NSLayoutConstraint *)object) autoInstall];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Deactivates the constraints in this array.
|
||||
*/
|
||||
- (void)autoRemoveConstraints
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) {
|
||||
[NSLayoutConstraint deactivateConstraints:self];
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[((NSLayoutConstraint *)object) autoRemove];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/**
|
||||
Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later.
|
||||
The identifier will be printed along with each constraint's description.
|
||||
This is helpful to document the constraints' purpose and aid in debugging.
|
||||
|
||||
@param identifier A string used to identify the constraints in this array.
|
||||
@return This array.
|
||||
*/
|
||||
- (instancetype)autoIdentifyConstraints:(NSString *)identifier
|
||||
{
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[((NSLayoutConstraint *)object) autoIdentify:identifier];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Array of Views
|
||||
|
||||
/**
|
||||
Aligns views in this array to one another along a given edge.
|
||||
Note: This array must contain at least 2 views, and all views must share a common superview.
|
||||
|
||||
@param edge The edge to which the views will be aligned.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (previousView) {
|
||||
[constraints addObject:[view autoPinEdge:edge toEdge:edge ofView:previousView]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Aligns views in this array to one another along a given axis.
|
||||
Note: This array must contain at least 2 views, and all views must share a common superview.
|
||||
|
||||
@param axis The axis to which the views will be aligned.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (previousView) {
|
||||
[constraints addObject:[view autoAlignAxis:axis toSameAxisOfView:previousView]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a given dimension of all the views in this array.
|
||||
Note: This array must contain at least 2 views, and all views must share a common superview.
|
||||
|
||||
@param dimension The dimension to match for all of the views.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (previousView) {
|
||||
[constraints addObject:[view autoMatchDimension:dimension toDimension:dimension ofView:previousView]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the given dimension of all the views in this array to a given size.
|
||||
Note: This array must contain at least 1 view.
|
||||
|
||||
@param dimension The dimension of each of the views to set.
|
||||
@param size The size to set the given dimension of each view to.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view.");
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[constraints addObject:[view autoSetDimension:dimension toSize:size]];
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets all of the views in this array to a given size.
|
||||
Note: This array must contain at least 1 view.
|
||||
|
||||
@param size The size to set each view's dimensions to.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size
|
||||
{
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
[constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionWidth toSize:size.width]];
|
||||
[constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionHeight toSize:size.height]];
|
||||
return constraints;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them,
|
||||
including from the first and last views to their superview.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param spacing The fixed amount of spacing between each view.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
{
|
||||
return [self autoDistributeViewsAlongAxis:axis
|
||||
alignedTo:alignment
|
||||
withFixedSpacing:spacing
|
||||
insetSpacing:YES];
|
||||
}
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them.
|
||||
The first and last views can optionally be inset from their superview by the same amount of spacing as between views.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param spacing The fixed amount of spacing between each view.
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
{
|
||||
return [self autoDistributeViewsAlongAxis:axis
|
||||
alignedTo:alignment
|
||||
withFixedSpacing:spacing
|
||||
insetSpacing:shouldSpaceInsets
|
||||
matchedSizes:YES];
|
||||
}
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will have fixed spacing between them, and can optionally be constrained to the same size in the dimension along the axis.
|
||||
The first and last views can optionally be inset from their superview by the same amount of spacing as between views.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param spacing The fixed amount of spacing between each view.
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@param shouldMatchSizes Whether all views will be constrained to be the same size in the dimension along the axis.
|
||||
NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous!
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
matchedSizes:(BOOL)shouldMatchSizes
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view to distribute.");
|
||||
ALDimension matchedDimension;
|
||||
ALEdge firstEdge, lastEdge;
|
||||
switch (axis) {
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
matchedDimension = ALDimensionWidth;
|
||||
firstEdge = ALEdgeLeading;
|
||||
lastEdge = ALEdgeTrailing;
|
||||
break;
|
||||
case ALAxisVertical:
|
||||
matchedDimension = ALDimensionHeight;
|
||||
firstEdge = ALEdgeTop;
|
||||
lastEdge = ALEdgeBottom;
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAxis.");
|
||||
return nil;
|
||||
}
|
||||
CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0;
|
||||
CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0;
|
||||
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (previousView) {
|
||||
// Second, Third, ... View
|
||||
[constraints addObject:[view autoPinEdge:firstEdge toEdge:lastEdge ofView:previousView withOffset:spacing]];
|
||||
if (shouldMatchSizes) {
|
||||
[constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]];
|
||||
}
|
||||
[constraints addObject:[view al_alignAttribute:alignment toView:previousView forAxis:axis]];
|
||||
}
|
||||
else {
|
||||
// First view
|
||||
[constraints addObject:[view autoPinEdgeToSuperviewEdge:firstEdge withInset:leadingSpacing]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
if (previousView) {
|
||||
// Last View
|
||||
[constraints addObject:[previousView autoPinEdgeToSuperviewEdge:lastEdge withInset:trailingSpacing]];
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them,
|
||||
including from the first and last views to their superview.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param size The fixed size of each view in the dimension along the given axis.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
{
|
||||
return [self autoDistributeViewsAlongAxis:axis
|
||||
alignedTo:alignment
|
||||
withFixedSize:size
|
||||
insetSpacing:YES];
|
||||
}
|
||||
|
||||
/**
|
||||
Distributes the views in this array equally along the selected axis in their superview.
|
||||
Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them.
|
||||
The first and last views can optionally be inset from their superview by the same amount of spacing as between views.
|
||||
|
||||
@param axis The axis along which to distribute the views.
|
||||
@param alignment The attribute to use to align all the views to one another.
|
||||
@param size The fixed size of each view in the dimension along the given axis.
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
{
|
||||
NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view to distribute.");
|
||||
ALDimension fixedDimension;
|
||||
NSLayoutAttribute attribute;
|
||||
switch (axis) {
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
fixedDimension = ALDimensionWidth;
|
||||
attribute = NSLayoutAttributeCenterX;
|
||||
break;
|
||||
case ALAxisVertical:
|
||||
fixedDimension = ALDimensionHeight;
|
||||
attribute = NSLayoutAttributeCenterY;
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAxis.");
|
||||
return nil;
|
||||
}
|
||||
#if TARGET_OS_IPHONE
|
||||
# if !defined(PURELAYOUT_APP_EXTENSIONS)
|
||||
BOOL isRightToLeftLayout = [[UIApplication sharedApplication] userInterfaceLayoutDirection] == UIUserInterfaceLayoutDirectionRightToLeft;
|
||||
# else
|
||||
// App Extensions may not access -[UIApplication sharedApplication]; fall back to checking the bundle's preferred localization character direction
|
||||
BOOL isRightToLeftLayout = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft;
|
||||
# endif /* !defined(PURELAYOUT_APP_EXTENSIONS) */
|
||||
#else
|
||||
BOOL isRightToLeftLayout = [[NSApplication sharedApplication] userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft;
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally
|
||||
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
__NSArray_of(ALView *) *views = [self al_copyViewsOnly];
|
||||
NSUInteger numberOfViews = [views count];
|
||||
ALView *commonSuperview = [views al_commonSuperviewOfViews];
|
||||
ALView *previousView = nil;
|
||||
for (NSUInteger i = 0; i < numberOfViews; i++) {
|
||||
ALView *view = shouldFlipOrder ? views[numberOfViews - i - 1] : views[i];
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[constraints addObject:[view autoSetDimension:fixedDimension toSize:size]];
|
||||
CGFloat multiplier, constant;
|
||||
if (shouldSpaceInsets) {
|
||||
multiplier = (i * 2.0 + 2.0) / (numberOfViews + 1.0);
|
||||
constant = (multiplier - 1.0) * size / 2.0;
|
||||
} else {
|
||||
multiplier = (i * 2.0) / (numberOfViews - 1.0);
|
||||
constant = (-multiplier + 1.0) * size / 2.0;
|
||||
}
|
||||
// If the multiplier is very close to 0, set it to the minimum value to prevent the second item in the constraint from being lost. Filed as rdar://19168380
|
||||
if (fabs(multiplier) < kMULTIPLIER_MIN_VALUE) {
|
||||
multiplier = kMULTIPLIER_MIN_VALUE;
|
||||
}
|
||||
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant];
|
||||
[constraint autoInstall];
|
||||
[constraints addObject:constraint];
|
||||
if (previousView) {
|
||||
[constraints addObject:[view al_alignAttribute:alignment toView:previousView forAxis:axis]];
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
#pragma mark Internal Helper Methods
|
||||
|
||||
/**
|
||||
Returns the common superview for the views in this array. If there is only one view in the array, its superview will be returned.
|
||||
Raises an exception if the views in this array do not share a common superview.
|
||||
|
||||
@return The common superview for the views in this array.
|
||||
*/
|
||||
- (ALView *)al_commonSuperviewOfViews
|
||||
{
|
||||
ALView *commonSuperview = nil;
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
if (previousView) {
|
||||
commonSuperview = [view al_commonSuperviewWithView:commonSuperview];
|
||||
} else {
|
||||
commonSuperview = view.superview;
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
}
|
||||
NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy.");
|
||||
return commonSuperview;
|
||||
}
|
||||
|
||||
/**
|
||||
Determines whether this array contains a minimum number of views.
|
||||
|
||||
@param minimumNumberOfViews The minimum number of views to check for.
|
||||
@return YES if this array contains at least the minimum number of views, NO otherwise.
|
||||
*/
|
||||
- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews
|
||||
{
|
||||
NSUInteger numberOfViews = 0;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
numberOfViews++;
|
||||
if (numberOfViews >= minimumNumberOfViews) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
return numberOfViews >= minimumNumberOfViews;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a copy of this array containing only the view objects in it.
|
||||
|
||||
@return A new array containing only the views that are in this array.
|
||||
*/
|
||||
- (__NSArray_of(ALView *) *)al_copyViewsOnly
|
||||
{
|
||||
__NSMutableArray_of(ALView *) *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]];
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
[viewsOnlyArray addObject:object];
|
||||
}
|
||||
}
|
||||
return viewsOnlyArray;
|
||||
}
|
||||
|
||||
@end
|
||||
84
Example/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h
generated
Executable file
@ -0,0 +1,84 @@
|
||||
//
|
||||
// NSLayoutConstraint+PureLayout.h
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
__PL_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark NSLayoutConstraint+PureLayout
|
||||
|
||||
/**
|
||||
A category on NSLayoutConstraint that allows constraints to be easily installed & removed.
|
||||
*/
|
||||
@interface NSLayoutConstraint (PureLayout)
|
||||
|
||||
|
||||
#pragma mark Batch Constraint Creation
|
||||
|
||||
/** Creates all of the constraints in the block, then installs (activates) them all at once.
|
||||
All constraints created from calls to the PureLayout API in the block are returned in a single array.
|
||||
This may be more efficient than installing (activating) each constraint one-by-one. */
|
||||
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block;
|
||||
|
||||
/** Creates all of the constraints in the block but prevents them from being automatically installed (activated).
|
||||
All constraints created from calls to the PureLayout API in the block are returned in a single array. */
|
||||
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block;
|
||||
|
||||
|
||||
#pragma mark Set Priority For Constraints
|
||||
|
||||
/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block.
|
||||
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */
|
||||
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block;
|
||||
|
||||
|
||||
#pragma mark Identify Constraints
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/** Sets the identifier for all constraints created using the PureLayout API within the given constraints block.
|
||||
NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */
|
||||
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block;
|
||||
|
||||
/** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */
|
||||
- (instancetype)autoIdentify:(NSString *)identifier;
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Install & Remove Constraints
|
||||
|
||||
/** Activates the the constraint. */
|
||||
- (void)autoInstall;
|
||||
|
||||
/** Deactivates the constraint. */
|
||||
- (void)autoRemove;
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
552
Example/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m
generated
Executable file
@ -0,0 +1,552 @@
|
||||
//
|
||||
// NSLayoutConstraint+PureLayout.m
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "NSArray+PureLayout.h"
|
||||
#import "PureLayout+Internal.h"
|
||||
|
||||
|
||||
#pragma mark - NSLayoutConstraint+PureLayout
|
||||
|
||||
@implementation NSLayoutConstraint (PureLayout)
|
||||
|
||||
#pragma mark Batch Constraint Creation
|
||||
|
||||
/**
|
||||
A global variable that stores a stack of arrays of constraints created without being immediately installed.
|
||||
When executing a constraints block passed into the +[autoCreateConstraintsWithoutInstalling:] method, a new
|
||||
mutable array is pushed onto this stack, and all constraints created with PureLayout in the block are added
|
||||
to this array. When the block finishes executing, the array is popped off this stack. Automatic constraint
|
||||
installation is prevented if this stack contains at least 1 array.
|
||||
|
||||
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
|
||||
*/
|
||||
static __NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *_al_arraysOfCreatedConstraints = nil;
|
||||
|
||||
/**
|
||||
A global variable that is set to YES when installing a batch of constraints collected from a call to +[autoCreateAndInstallConstraints].
|
||||
When this flag is YES, constraints are installed immediately without checking for or adding to the +[al_currentArrayOfCreatedConstraints].
|
||||
This is necessary to properly handle nested calls to +[autoCreateAndInstallConstraints], where calls whose block contains other call(s)
|
||||
should not return constraints from within the blocks of nested call(s).
|
||||
*/
|
||||
static BOOL _al_isInstallingCreatedConstraints = NO;
|
||||
|
||||
/**
|
||||
Accessor for the global state that stores arrays of constraints created without being installed.
|
||||
*/
|
||||
+ (__NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *)al_arraysOfCreatedConstraints
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
|
||||
if (!_al_arraysOfCreatedConstraints) {
|
||||
_al_arraysOfCreatedConstraints = [NSMutableArray new];
|
||||
}
|
||||
return _al_arraysOfCreatedConstraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Accessor for the current mutable array of constraints created without being immediately installed.
|
||||
*/
|
||||
+ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints
|
||||
{
|
||||
return [[self al_arraysOfCreatedConstraints] lastObject];
|
||||
}
|
||||
|
||||
/**
|
||||
Accessor for the global state that determines whether automatic constraint installation should be prevented.
|
||||
*/
|
||||
+ (BOOL)al_preventAutomaticConstraintInstallation
|
||||
{
|
||||
return (_al_isInstallingCreatedConstraints == NO) && ([[self al_arraysOfCreatedConstraints] count] > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates all of the constraints in the block, then installs (activates) them all at once.
|
||||
All constraints created from calls to the PureLayout API in the block are returned in a single array.
|
||||
This may be more efficient than installing (activating) each constraint one-by-one.
|
||||
|
||||
Note: calls to this method may be nested. The constraints returned from a call will NOT include constraints
|
||||
created in nested calls; constraints are only returned from the inner-most call they are created within.
|
||||
|
||||
@param block A block of method calls to the PureLayout API that create constraints.
|
||||
@return An array of the constraints that were created from calls to the PureLayout API inside the block.
|
||||
*/
|
||||
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block
|
||||
{
|
||||
NSArray *createdConstraints = [self autoCreateConstraintsWithoutInstalling:block];
|
||||
_al_isInstallingCreatedConstraints = YES;
|
||||
[createdConstraints autoInstallConstraints];
|
||||
_al_isInstallingCreatedConstraints = NO;
|
||||
return createdConstraints;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates all of the constraints in the block but prevents them from being automatically installed (activated).
|
||||
All constraints created from calls to the PureLayout API in the block are returned in a single array.
|
||||
|
||||
Note: calls to this method may be nested. The constraints returned from a call will NOT include constraints
|
||||
created in nested calls; constraints are only returned from the inner-most call they are created within.
|
||||
|
||||
@param block A block of method calls to the PureLayout API that create constraints.
|
||||
@return An array of the constraints that were created from calls to the PureLayout API inside the block.
|
||||
*/
|
||||
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block
|
||||
{
|
||||
NSAssert(block, @"The constraints block cannot be nil.");
|
||||
NSArray *createdConstraints = nil;
|
||||
if (block) {
|
||||
[[self al_arraysOfCreatedConstraints] addObject:[NSMutableArray new]];
|
||||
block();
|
||||
createdConstraints = [self al_currentArrayOfCreatedConstraints];
|
||||
[[self al_arraysOfCreatedConstraints] removeLastObject];
|
||||
}
|
||||
return createdConstraints;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Set Priority For Constraints
|
||||
|
||||
/**
|
||||
A global variable that stores a stack of layout priorities to set on constraints.
|
||||
When executing a constraints block passed into the +[autoSetPriority:forConstraints:] method, the priority for
|
||||
that call is pushed onto this stack, and when the block finishes executing, that priority is popped off this
|
||||
stack. If this stack contains at least 1 priority, the priority at the top of the stack will be set for all
|
||||
constraints created by this library (even if automatic constraint installation is being prevented).
|
||||
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
|
||||
*/
|
||||
static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil;
|
||||
|
||||
/**
|
||||
Accessor for the global stack of layout priorities.
|
||||
*/
|
||||
+ (__NSMutableArray_of(NSNumber *) *)al_globalConstraintPriorities
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
|
||||
if (!_al_globalConstraintPriorities) {
|
||||
_al_globalConstraintPriorities = [NSMutableArray new];
|
||||
}
|
||||
return _al_globalConstraintPriorities;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the current layout priority to use for constraints.
|
||||
When executing a constraints block passed into +[autoSetPriority:forConstraints:], this will return
|
||||
the priority for the current block. Otherwise, the default Required priority is returned.
|
||||
*/
|
||||
+ (ALLayoutPriority)al_currentGlobalConstraintPriority
|
||||
{
|
||||
__NSMutableArray_of(NSNumber *) *globalConstraintPriorities = [self al_globalConstraintPriorities];
|
||||
if ([globalConstraintPriorities count] == 0) {
|
||||
return ALLayoutPriorityRequired;
|
||||
}
|
||||
return [[globalConstraintPriorities lastObject] floatValue];
|
||||
}
|
||||
|
||||
/**
|
||||
Accessor for the global state that determines if we're currently in the scope of a priority constraints block.
|
||||
*/
|
||||
+ (BOOL)al_isExecutingPriorityConstraintsBlock
|
||||
{
|
||||
return [[self al_globalConstraintPriorities] count] > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the constraint priority to the given value for all constraints created using the PureLayout
|
||||
API within the given constraints block.
|
||||
|
||||
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added
|
||||
without using the PureLayout API!
|
||||
|
||||
@param priority The layout priority to be set on all constraints created in the constraints block.
|
||||
@param block A block of method calls to the PureLayout API that create and install constraints.
|
||||
*/
|
||||
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block
|
||||
{
|
||||
NSAssert(block, @"The constraints block cannot be nil.");
|
||||
if (block) {
|
||||
[[self al_globalConstraintPriorities] addObject:@(priority)];
|
||||
block();
|
||||
[[self al_globalConstraintPriorities] removeLastObject];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Identify Constraints
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
|
||||
/**
|
||||
A global variable that stores a stack of identifier strings to set on constraints.
|
||||
When executing a constraints block passed into the +[autoSetIdentifier:forConstraints:] method, the identifier for
|
||||
that call is pushed onto this stack, and when the block finishes executing, that identifier is popped off this
|
||||
stack. If this stack contains at least 1 identifier, the identifier at the top of the stack will be set for all
|
||||
constraints created by this library (even if automatic constraint installation is being prevented).
|
||||
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
|
||||
*/
|
||||
static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
|
||||
|
||||
/**
|
||||
Accessor for the global state of constraint identifiers.
|
||||
*/
|
||||
+ (__NSMutableArray_of(NSString *) *)al_globalConstraintIdentifiers
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
|
||||
if (!_al_globalConstraintIdentifiers) {
|
||||
_al_globalConstraintIdentifiers = [NSMutableArray new];
|
||||
}
|
||||
return _al_globalConstraintIdentifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the current identifier string to use for constraints.
|
||||
When executing a constraints block passed into +[autoSetIdentifier:forConstraints:], this will return
|
||||
the identifier for the current block. Otherwise, nil is returned.
|
||||
*/
|
||||
+ (NSString *)al_currentGlobalConstraintIdentifier
|
||||
{
|
||||
__NSMutableArray_of(NSString *) *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers];
|
||||
if ([globalConstraintIdentifiers count] == 0) {
|
||||
return nil;
|
||||
}
|
||||
return [globalConstraintIdentifiers lastObject];
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the identifier for all constraints created using the PureLayout API within the given constraints block.
|
||||
|
||||
NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added
|
||||
without using the PureLayout API!
|
||||
|
||||
@param identifier A string used to identify all constraints created in the constraints block.
|
||||
@param block A block of method calls to the PureLayout API that create and install constraints.
|
||||
*/
|
||||
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block
|
||||
{
|
||||
NSAssert(block, @"The constraints block cannot be nil.");
|
||||
NSAssert(identifier, @"The identifier string cannot be nil.");
|
||||
if (block) {
|
||||
if (identifier) {
|
||||
[[self al_globalConstraintIdentifiers] addObject:identifier];
|
||||
}
|
||||
block();
|
||||
if (identifier) {
|
||||
[[self al_globalConstraintIdentifiers] removeLastObject];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later.
|
||||
The identifier will be printed along with the constraint's description.
|
||||
This is helpful to document a constraint's purpose and aid in debugging.
|
||||
|
||||
@param identifier A string used to identify this constraint.
|
||||
@return This constraint.
|
||||
*/
|
||||
- (instancetype)autoIdentify:(NSString *)identifier
|
||||
{
|
||||
if ([self respondsToSelector:@selector(setIdentifier:)]) {
|
||||
self.identifier = identifier;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Install & Remove Constraints
|
||||
|
||||
/**
|
||||
Activates the constraint.
|
||||
*/
|
||||
- (void)autoInstall
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([self respondsToSelector:@selector(setActive:)]) {
|
||||
[NSLayoutConstraint al_applyGlobalStateToConstraint:self];
|
||||
if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
|
||||
[[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:self];
|
||||
} else {
|
||||
self.active = YES;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem.");
|
||||
if (self.firstItem) {
|
||||
if (self.secondItem) {
|
||||
NSAssert([self.firstItem isKindOfClass:[ALView class]] && [self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if both items are views.");
|
||||
ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem];
|
||||
[commonSuperview al_addConstraint:self];
|
||||
} else {
|
||||
NSAssert([self.firstItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view.");
|
||||
[self.firstItem al_addConstraint:self];
|
||||
}
|
||||
} else {
|
||||
NSAssert([self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view.");
|
||||
[self.secondItem al_addConstraint:self];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Deactivates the constraint.
|
||||
*/
|
||||
- (void)autoRemove
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([self respondsToSelector:@selector(setActive:)]) {
|
||||
self.active = NO;
|
||||
return;
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
if (self.secondItem) {
|
||||
ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem];
|
||||
while (commonSuperview) {
|
||||
if ([commonSuperview.constraints containsObject:self]) {
|
||||
[commonSuperview removeConstraint:self];
|
||||
return;
|
||||
}
|
||||
commonSuperview = commonSuperview.superview;
|
||||
}
|
||||
}
|
||||
else {
|
||||
[self.firstItem removeConstraint:self];
|
||||
return;
|
||||
}
|
||||
NSAssert(nil, @"Failed to remove constraint: %@", self);
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Internal Methods
|
||||
|
||||
/**
|
||||
Applies the global constraint priority and identifier to the given constraint.
|
||||
This should be done before installing all constraints.
|
||||
|
||||
@param constraint The constraint to set the global priority and identifier on.
|
||||
*/
|
||||
+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint
|
||||
{
|
||||
if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
|
||||
constraint.priority = [NSLayoutConstraint al_currentGlobalConstraintPriority];
|
||||
}
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
NSString *globalConstraintIdentifier = [NSLayoutConstraint al_currentGlobalConstraintIdentifier];
|
||||
if (globalConstraintIdentifier) {
|
||||
[constraint autoIdentify:globalConstraintIdentifier];
|
||||
}
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the corresponding NSLayoutAttribute for the given ALAttribute.
|
||||
|
||||
@return The layout attribute for the given ALAttribute.
|
||||
*/
|
||||
+ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute
|
||||
{
|
||||
NSLayoutAttribute layoutAttribute = NSLayoutAttributeNotAnAttribute;
|
||||
switch (attribute) {
|
||||
case ALEdgeLeft:
|
||||
layoutAttribute = NSLayoutAttributeLeft;
|
||||
break;
|
||||
case ALEdgeRight:
|
||||
layoutAttribute = NSLayoutAttributeRight;
|
||||
break;
|
||||
case ALEdgeTop:
|
||||
layoutAttribute = NSLayoutAttributeTop;
|
||||
break;
|
||||
case ALEdgeBottom:
|
||||
layoutAttribute = NSLayoutAttributeBottom;
|
||||
break;
|
||||
case ALEdgeLeading:
|
||||
layoutAttribute = NSLayoutAttributeLeading;
|
||||
break;
|
||||
case ALEdgeTrailing:
|
||||
layoutAttribute = NSLayoutAttributeTrailing;
|
||||
break;
|
||||
case ALDimensionWidth:
|
||||
layoutAttribute = NSLayoutAttributeWidth;
|
||||
break;
|
||||
case ALDimensionHeight:
|
||||
layoutAttribute = NSLayoutAttributeHeight;
|
||||
break;
|
||||
case ALAxisVertical:
|
||||
layoutAttribute = NSLayoutAttributeCenterX;
|
||||
break;
|
||||
case ALAxisHorizontal:
|
||||
layoutAttribute = NSLayoutAttributeCenterY;
|
||||
break;
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
layoutAttribute = NSLayoutAttributeBaseline;
|
||||
break;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisFirstBaseline is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeFirstBaseline;
|
||||
break;
|
||||
case ALMarginLeft:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeftMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeLeftMargin;
|
||||
break;
|
||||
case ALMarginRight:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeRightMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeRightMargin;
|
||||
break;
|
||||
case ALMarginTop:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTopMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeTopMargin;
|
||||
break;
|
||||
case ALMarginBottom:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeBottomMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeBottomMargin;
|
||||
break;
|
||||
case ALMarginLeading:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeadingMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeLeadingMargin;
|
||||
break;
|
||||
case ALMarginTrailing:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTrailingMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeTrailingMargin;
|
||||
break;
|
||||
case ALMarginAxisVertical:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisVerticalMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeCenterXWithinMargins;
|
||||
break;
|
||||
case ALMarginAxisHorizontal:
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisHorizontalMargin is only supported on iOS 8.0 or higher.");
|
||||
layoutAttribute = NSLayoutAttributeCenterYWithinMargins;
|
||||
break;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAttribute.");
|
||||
break;
|
||||
}
|
||||
return layoutAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the corresponding ALLayoutConstraintAxis for the given ALAxis.
|
||||
|
||||
@return The constraint axis for the given axis.
|
||||
*/
|
||||
+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis
|
||||
{
|
||||
ALLayoutConstraintAxis constraintAxis;
|
||||
switch (axis) {
|
||||
case ALAxisVertical:
|
||||
constraintAxis = ALLayoutConstraintAxisVertical;
|
||||
break;
|
||||
case ALAxisHorizontal:
|
||||
case ALAxisBaseline: // same value as ALAxisLastBaseline
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
case ALAxisFirstBaseline:
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
constraintAxis = ALLayoutConstraintAxisHorizontal;
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAxis.");
|
||||
constraintAxis = ALLayoutConstraintAxisHorizontal; // default to an arbitrary value to satisfy the compiler
|
||||
break;
|
||||
}
|
||||
return constraintAxis;
|
||||
}
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/**
|
||||
Returns the corresponding margin for the given edge.
|
||||
|
||||
@param edge The edge to convert to the corresponding margin.
|
||||
@return The margin for the given edge.
|
||||
*/
|
||||
+ (ALMargin)al_marginForEdge:(ALEdge)edge
|
||||
{
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher.");
|
||||
ALMargin margin;
|
||||
switch (edge) {
|
||||
case ALEdgeLeft:
|
||||
margin = ALMarginLeft;
|
||||
break;
|
||||
case ALEdgeRight:
|
||||
margin = ALMarginRight;
|
||||
break;
|
||||
case ALEdgeTop:
|
||||
margin = ALMarginTop;
|
||||
break;
|
||||
case ALEdgeBottom:
|
||||
margin = ALMarginBottom;
|
||||
break;
|
||||
case ALEdgeLeading:
|
||||
margin = ALMarginLeading;
|
||||
break;
|
||||
case ALEdgeTrailing:
|
||||
margin = ALMarginTrailing;
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALEdge.");
|
||||
margin = ALMarginLeft; // default to an arbitrary value to satisfy the compiler
|
||||
break;
|
||||
}
|
||||
return margin;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the corresponding margin axis for the given axis.
|
||||
|
||||
@param axis The axis to convert to the corresponding margin axis.
|
||||
@return The margin axis for the given axis.
|
||||
*/
|
||||
+ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher.");
|
||||
ALMarginAxis marginAxis;
|
||||
switch (axis) {
|
||||
case ALAxisVertical:
|
||||
marginAxis = ALMarginAxisVertical;
|
||||
break;
|
||||
case ALAxisHorizontal:
|
||||
marginAxis = ALMarginAxisHorizontal;
|
||||
break;
|
||||
case ALAxisBaseline:
|
||||
case ALAxisFirstBaseline:
|
||||
NSAssert(nil, @"The baseline axis attributes do not have corresponding margin axis attributes.");
|
||||
marginAxis = ALMarginAxisVertical; // default to an arbitrary value to satisfy the compiler
|
||||
break;
|
||||
default:
|
||||
NSAssert(nil, @"Not a valid ALAxis.");
|
||||
marginAxis = ALMarginAxisVertical; // default to an arbitrary value to satisfy the compiler
|
||||
break;
|
||||
}
|
||||
return marginAxis;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
@end
|
||||
87
Example/Pods/PureLayout/PureLayout/PureLayout/PureLayout+Internal.h
generated
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// PureLayout+Internal.h
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2014-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
|
||||
// Using generics with NSMutableArray is so common in the internal implementation of PureLayout that it gets a dedicated preprocessor macro for better readability.
|
||||
#define __NSMutableArray_of(type) __PL_GENERICS(NSMutableArray, type)
|
||||
|
||||
__PL_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/** A constant that represents the smallest valid positive value for the multiplier of a constraint,
|
||||
since a value of 0 will cause the second item to be lost in the internal auto layout engine. */
|
||||
static const CGFloat kMULTIPLIER_MIN_VALUE = (CGFloat)0.00001; // very small floating point numbers (e.g. CGFLOAT_MIN) can cause problems
|
||||
|
||||
|
||||
/**
|
||||
A category that exposes the internal (private) helper methods of the ALView+PureLayout category.
|
||||
*/
|
||||
@interface ALView (PureLayoutInternal)
|
||||
|
||||
- (void)al_addConstraint:(NSLayoutConstraint *)constraint;
|
||||
- (ALView *)al_commonSuperviewWithView:(ALView *)otherView;
|
||||
- (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
A category that exposes the internal (private) helper methods of the NSArray+PureLayout category.
|
||||
*/
|
||||
@interface NSArray (PureLayoutInternal)
|
||||
|
||||
- (ALView *)al_commonSuperviewOfViews;
|
||||
- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews;
|
||||
- (__NSArray_of(ALView *) *)al_copyViewsOnly;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
A category that exposes the internal (private) helper methods of the NSLayoutConstraint+PureLayout category.
|
||||
*/
|
||||
@interface NSLayoutConstraint (PureLayoutInternal)
|
||||
|
||||
+ (BOOL)al_preventAutomaticConstraintInstallation;
|
||||
+ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints;
|
||||
+ (BOOL)al_isExecutingPriorityConstraintsBlock;
|
||||
+ (ALLayoutPriority)al_currentGlobalConstraintPriority;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
+ (NSString *)al_currentGlobalConstraintIdentifier;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint;
|
||||
+ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute;
|
||||
+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
+ (ALMargin)al_marginForEdge:(ALEdge)edge;
|
||||
+ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis;
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
43
Example/Pods/PureLayout/PureLayout/PureLayout/PureLayout.h
generated
Executable file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// PureLayout.h
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2014-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef PureLayout_h
|
||||
#define PureLayout_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//! Project version number for PureLayout.
|
||||
FOUNDATION_EXPORT double PureLayoutVersionNumber;
|
||||
|
||||
//! Project version string for PureLayout.
|
||||
FOUNDATION_EXPORT const unsigned char PureLayoutVersionString[];
|
||||
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "NSArray+PureLayout.h"
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
|
||||
#endif /* PureLayout_h */
|
||||
224
Example/Pods/PureLayout/PureLayout/PureLayout/PureLayoutDefines.h
generated
Executable file
@ -0,0 +1,224 @@
|
||||
//
|
||||
// PureLayoutDefines.h
|
||||
// https://github.com/PureLayout/PureLayout
|
||||
//
|
||||
// Copyright (c) 2014-2015 Tyler Fox
|
||||
//
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef PureLayoutDefines_h
|
||||
#define PureLayoutDefines_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// Define some preprocessor macros to check for a minimum Base SDK. These are used to prevent compile-time errors in older versions of Xcode.
|
||||
#define __PureLayout_MinBaseSDK_iOS_8_0 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1)
|
||||
#define __PureLayout_MinBaseSDK_OSX_10_10 (!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9)
|
||||
|
||||
// Define some preprocessor macros to check for a minimum System Version. These are used to prevent runtime crashes on older versions of iOS/OS X.
|
||||
#define __PureLayout_MinSysVer_iOS_7_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
|
||||
#define __PureLayout_MinSysVer_iOS_8_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
|
||||
#define __PureLayout_MinSysVer_OSX_10_9 (!TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4)
|
||||
|
||||
// Define some preprocessor macros that allow nullability annotations to be adopted in a backwards-compatible manner.
|
||||
#if __has_feature(nullability)
|
||||
# define __PL_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
|
||||
# define __PL_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
|
||||
#else
|
||||
# define __PL_ASSUME_NONNULL_BEGIN
|
||||
# define __PL_ASSUME_NONNULL_END
|
||||
#endif
|
||||
|
||||
// Define some preprocessor macros that allow generics to be adopted in a backwards-compatible manner.
|
||||
#if __has_feature(objc_generics)
|
||||
# define __PL_GENERICS(class, ...) class<__VA_ARGS__>
|
||||
#else
|
||||
# define __PL_GENERICS(class, ...) class
|
||||
#endif
|
||||
|
||||
// Using generics with NSArray is so common in PureLayout that it gets a dedicated preprocessor macro for better readability.
|
||||
#define __NSArray_of(type) __PL_GENERICS(NSArray, type)
|
||||
|
||||
// Define generic AL-prefixed macros for the types/constants/etc that have slight naming variations across iOS and OS X, which allows the same code to be platform-independent.
|
||||
#if TARGET_OS_IPHONE
|
||||
# import <UIKit/UIKit.h>
|
||||
# define ALView UIView
|
||||
# define ALEdgeInsets UIEdgeInsets
|
||||
# define ALEdgeInsetsZero UIEdgeInsetsZero
|
||||
# define ALEdgeInsetsMake UIEdgeInsetsMake
|
||||
# define ALLayoutConstraintAxis UILayoutConstraintAxis
|
||||
# define ALLayoutConstraintOrientation ALLayoutConstraintAxis
|
||||
# define ALLayoutConstraintAxisHorizontal UILayoutConstraintAxisHorizontal
|
||||
# define ALLayoutConstraintAxisVertical UILayoutConstraintAxisVertical
|
||||
# define ALLayoutConstraintOrientationHorizontal ALLayoutConstraintAxisHorizontal
|
||||
# define ALLayoutConstraintOrientationVertical ALLayoutConstraintAxisVertical
|
||||
# define ALLayoutPriority UILayoutPriority
|
||||
# define ALLayoutPriorityRequired UILayoutPriorityRequired
|
||||
# define ALLayoutPriorityDefaultHigh UILayoutPriorityDefaultHigh
|
||||
# define ALLayoutPriorityDefaultLow UILayoutPriorityDefaultLow
|
||||
# define ALLayoutPriorityFittingSizeLevel UILayoutPriorityFittingSizeLevel
|
||||
# define ALLayoutPriorityFittingSizeCompression ALLayoutPriorityFittingSizeLevel
|
||||
#else
|
||||
# import <Cocoa/Cocoa.h>
|
||||
# define ALView NSView
|
||||
# define ALEdgeInsets NSEdgeInsets
|
||||
# define ALEdgeInsetsZero NSEdgeInsetsMake(0, 0, 0, 0)
|
||||
# define ALEdgeInsetsMake NSEdgeInsetsMake
|
||||
# define ALLayoutConstraintOrientation NSLayoutConstraintOrientation
|
||||
# define ALLayoutConstraintAxis ALLayoutConstraintOrientation
|
||||
# define ALLayoutConstraintOrientationHorizontal NSLayoutConstraintOrientationHorizontal
|
||||
# define ALLayoutConstraintOrientationVertical NSLayoutConstraintOrientationVertical
|
||||
# define ALLayoutConstraintAxisHorizontal ALLayoutConstraintOrientationHorizontal
|
||||
# define ALLayoutConstraintAxisVertical ALLayoutConstraintOrientationVertical
|
||||
# define ALLayoutPriority NSLayoutPriority
|
||||
# define ALLayoutPriorityRequired NSLayoutPriorityRequired
|
||||
# define ALLayoutPriorityDefaultHigh NSLayoutPriorityDefaultHigh
|
||||
# define ALLayoutPriorityDefaultLow NSLayoutPriorityDefaultLow
|
||||
# define ALLayoutPriorityFittingSizeCompression NSLayoutPriorityFittingSizeCompression
|
||||
# define ALLayoutPriorityFittingSizeLevel ALLayoutPriorityFittingSizeCompression
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
|
||||
|
||||
#pragma mark PureLayout Attributes
|
||||
|
||||
/** Constants that represent edges of a view. */
|
||||
typedef NS_ENUM(NSInteger, ALEdge) {
|
||||
/** The left edge of the view. */
|
||||
ALEdgeLeft = NSLayoutAttributeLeft,
|
||||
/** The right edge of the view. */
|
||||
ALEdgeRight = NSLayoutAttributeRight,
|
||||
/** The top edge of the view. */
|
||||
ALEdgeTop = NSLayoutAttributeTop,
|
||||
/** The bottom edge of the view. */
|
||||
ALEdgeBottom = NSLayoutAttributeBottom,
|
||||
/** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */
|
||||
ALEdgeLeading = NSLayoutAttributeLeading,
|
||||
/** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */
|
||||
ALEdgeTrailing = NSLayoutAttributeTrailing
|
||||
};
|
||||
|
||||
/** Constants that represent dimensions of a view. */
|
||||
typedef NS_ENUM(NSInteger, ALDimension) {
|
||||
/** The width of the view. */
|
||||
ALDimensionWidth = NSLayoutAttributeWidth,
|
||||
/** The height of the view. */
|
||||
ALDimensionHeight = NSLayoutAttributeHeight
|
||||
};
|
||||
|
||||
/** Constants that represent axes of a view. */
|
||||
typedef NS_ENUM(NSInteger, ALAxis) {
|
||||
/** A vertical line equidistant from the view's left and right edges. */
|
||||
ALAxisVertical = NSLayoutAttributeCenterX,
|
||||
/** A horizontal line equidistant from the view's top and bottom edges. */
|
||||
ALAxisHorizontal = NSLayoutAttributeCenterY,
|
||||
|
||||
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */
|
||||
ALAxisBaseline = NSLayoutAttributeBaseline,
|
||||
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */
|
||||
ALAxisLastBaseline = ALAxisBaseline,
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
/** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */
|
||||
ALAxisFirstBaseline = NSLayoutAttributeFirstBaseline
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
};
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** Constants that represent layout margins of a view. Available in iOS 8.0 and later. */
|
||||
typedef NS_ENUM(NSInteger, ALMargin) {
|
||||
/** The left margin of the view, based on the view's layoutMargins left inset. */
|
||||
ALMarginLeft = NSLayoutAttributeLeftMargin,
|
||||
/** The right margin of the view, based on the view's layoutMargins right inset. */
|
||||
ALMarginRight = NSLayoutAttributeRightMargin,
|
||||
/** The top margin of the view, based on the view's layoutMargins top inset. */
|
||||
ALMarginTop = NSLayoutAttributeTopMargin,
|
||||
/** The bottom margin of the view, based on the view's layoutMargins bottom inset. */
|
||||
ALMarginBottom = NSLayoutAttributeBottomMargin,
|
||||
/** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
ALMarginLeading = NSLayoutAttributeLeadingMargin,
|
||||
/** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
ALMarginTrailing = NSLayoutAttributeTrailingMargin
|
||||
};
|
||||
|
||||
/** Constants that represent axes of the layout margins of a view. Available in iOS 8.0 and later. */
|
||||
typedef NS_ENUM(NSInteger, ALMarginAxis) {
|
||||
/** A vertical line equidistant from the view's left and right margins. */
|
||||
ALMarginAxisVertical = NSLayoutAttributeCenterXWithinMargins,
|
||||
/** A horizontal line equidistant from the view's top and bottom margins. */
|
||||
ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins
|
||||
};
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
|
||||
/** An attribute of a view that can be used in auto layout constraints. These constants are identical to the more specific enum types:
|
||||
ALEdge, ALAxis, ALDimension, ALMargin, ALMarginAxis. It is safe to cast a more specific enum type to the ALAttribute type. */
|
||||
typedef NS_ENUM(NSInteger, ALAttribute) {
|
||||
/** The left edge of the view. */
|
||||
ALAttributeLeft = ALEdgeLeft,
|
||||
/** The right edge of the view. */
|
||||
ALAttributeRight = ALEdgeRight,
|
||||
/** The top edge of the view. */
|
||||
ALAttributeTop = ALEdgeTop,
|
||||
/** The bottom edge of the view. */
|
||||
ALAttributeBottom = ALEdgeBottom,
|
||||
/** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */
|
||||
ALAttributeLeading = ALEdgeLeading,
|
||||
/** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */
|
||||
ALAttributeTrailing = ALEdgeTrailing,
|
||||
/** The width of the view. */
|
||||
ALAttributeWidth = ALDimensionWidth,
|
||||
/** The height of the view. */
|
||||
ALAttributeHeight = ALDimensionHeight,
|
||||
/** A vertical line equidistant from the view's left and right edges. */
|
||||
ALAttributeVertical = ALAxisVertical,
|
||||
/** A horizontal line equidistant from the view's top and bottom edges. */
|
||||
ALAttributeHorizontal = ALAxisHorizontal,
|
||||
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */
|
||||
ALAttributeBaseline = ALAxisBaseline,
|
||||
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */
|
||||
ALAttributeLastBaseline = ALAxisLastBaseline,
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
/** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */
|
||||
ALAttributeFirstBaseline = ALAxisFirstBaseline,
|
||||
/** The left margin of the view, based on the view's layoutMargins left inset. */
|
||||
ALAttributeMarginLeft = ALMarginLeft,
|
||||
/** The right margin of the view, based on the view's layoutMargins right inset. */
|
||||
ALAttributeMarginRight = ALMarginRight,
|
||||
/** The top margin of the view, based on the view's layoutMargins top inset. */
|
||||
ALAttributeMarginTop = ALMarginTop,
|
||||
/** The bottom margin of the view, based on the view's layoutMargins bottom inset. */
|
||||
ALAttributeMarginBottom = ALMarginBottom,
|
||||
/** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
ALAttributeMarginLeading = ALMarginLeading,
|
||||
/** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
ALAttributeMarginTrailing = ALMarginTrailing,
|
||||
/** A vertical line equidistant from the view's left and right margins. */
|
||||
ALAttributeMarginAxisVertical = ALMarginAxisVertical,
|
||||
/** A horizontal line equidistant from the view's top and bottom margins. */
|
||||
ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
};
|
||||
|
||||
/** A block containing method calls to the PureLayout API. Takes no arguments and has no return value. */
|
||||
typedef void(^ALConstraintsBlock)(void);
|
||||
|
||||
#endif /* PureLayoutDefines_h */
|
||||
219
Example/Pods/PureLayout/README.md
generated
Normal file
@ -0,0 +1,219 @@
|
||||
# [](#)
|
||||
[](https://travis-ci.org/PureLayout/PureLayout) [](https://coveralls.io/r/PureLayout/PureLayout) [](http://cocoapods.org/?q=PureLayout) [](http://cocoapods.org/?q=PureLayout) [](LICENSE)
|
||||
|
||||
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. PureLayout extends `UIView`/`NSView`, `NSArray`, and `NSLayoutConstraint` with a comprehensive Auto Layout API that is modeled after Apple's own frameworks. PureLayout is a cross-platform Objective-C library that works (and looks!) great in Swift. It is fully backwards-compatible with all versions of iOS and OS X that support Auto Layout.
|
||||
|
||||
Writing Auto Layout code from scratch isn't easy. PureLayout provides a fully capable and developer-friendly interface for Auto Layout. It is designed for clarity and simplicity, and takes inspiration from the AutoLayout UI options available in Interface Builder while delivering far more flexibility. The API is also highly efficient, as it adds only a thin layer of third party code and is engineered for maximum performance.
|
||||
|
||||
### Table of Contents
|
||||
1. [Setup](#setup)
|
||||
1. [API Cheat Sheet](#api-cheat-sheet)
|
||||
1. [Usage](#usage)
|
||||
* [Sample Code](#sample-code-swift)
|
||||
* [Example Apps](#example-apps)
|
||||
1. [PureLayout vs. the rest](#purelayout-vs-the-rest)
|
||||
1. [Problems, Suggestions, Pull Requests?](#problems-suggestions-pull-requests)
|
||||
|
||||
## Setup
|
||||
### Compatibility
|
||||
The current release of PureLayout supports all versions of iOS and OS X since the introduction of Auto Layout on each platform, in both Swift and Objective-C, with a single codebase!
|
||||
|
||||
* Xcode
|
||||
* Language Support: **Swift** *(any version)*, **Objective-C**
|
||||
* Fully Compatible With: **Xcode 7.0**
|
||||
* Minimum Supported Version: **Xcode 5.0**
|
||||
* iOS
|
||||
* Fully Compatible With: **iOS 9.0**
|
||||
* Minimum Deployment Target: **iOS 6.0**
|
||||
* OS X
|
||||
* Fully Compatible With: **OS X 10.11**
|
||||
* Minimum Deployment Target: **OS X 10.7**
|
||||
|
||||
### Using [CocoaPods](http://cocoapods.org)
|
||||
1. Add the pod `PureLayout` to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html).
|
||||
|
||||
```ruby
|
||||
pod 'PureLayout'
|
||||
```
|
||||
|
||||
1. Run `pod install` from Terminal, then open your app's `.xcworkspace` file to launch Xcode.
|
||||
1. Import the `PureLayout.h` umbrella header.
|
||||
* With `use_frameworks!` in your Podfile
|
||||
* Swift: `import PureLayout`
|
||||
* Objective-C: `#import <PureLayout/PureLayout.h>` (or with Modules enabled: `@import PureLayout;`)
|
||||
* Without `use_frameworks!` in your Podfile
|
||||
* Swift: Add `#import "PureLayout.h"` to your bridging header.
|
||||
* Objective-C: `#import "PureLayout.h"`
|
||||
|
||||
That's it - now go write some beautiful Auto Layout code!
|
||||
|
||||
### Using [Carthage](https://github.com/Carthage/Carthage)
|
||||
1. Add the `PureLayout/PureLayout` project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile).
|
||||
|
||||
```ogdl
|
||||
github "PureLayout/PureLayout"
|
||||
```
|
||||
|
||||
1. Run `carthage update`, then follow the [additional steps required](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to add the framework into your project.
|
||||
1. Import the PureLayout framework/module.
|
||||
* Swift: `import PureLayout`
|
||||
* Objective-C: `#import <PureLayout/PureLayout.h>` (or with Modules enabled: `@import PureLayout;`)
|
||||
|
||||
That's it - now go write some beautiful Auto Layout code!
|
||||
|
||||
### Manually from GitHub
|
||||
1. Download the source files in the [PureLayout subdirectory](PureLayout/PureLayout).
|
||||
1. Add the source files to your Xcode project.
|
||||
1. Import the `PureLayout.h` header.
|
||||
* Swift: Add `#import "PureLayout.h"` to your bridging header.
|
||||
* Objective-C: `#import "PureLayout.h"`
|
||||
|
||||
That's it - now go write some beautiful Auto Layout code!
|
||||
|
||||
### App Extensions
|
||||
To use PureLayout in an App Extension, you need to do a bit of extra configuration to prevent usage of unavailable APIs. [Click here](https://github.com/PureLayout/PureLayout/wiki/App-Extensions) for more info.
|
||||
|
||||
### Releases
|
||||
Releases are tagged in the git commit history using [semantic versioning](http://semver.org). Check out the [releases and release notes](https://github.com/PureLayout/PureLayout/releases) for each version.
|
||||
|
||||
## API Cheat Sheet
|
||||
This is just a handy overview of the core API methods. Explore the [header files](PureLayout/PureLayout) for the full API, and find the complete documentation above the implementation of each method in the corresponding .m file. A couple of notes:
|
||||
|
||||
* All of the public API methods are namespaced with the prefix `auto...`, which also makes it easy for Xcode to autocomplete as you type.
|
||||
* Methods that create constraints also automatically install (activate) the constraint(s), then return the new constraint(s) for you to optionally store for later adjustment or removal.
|
||||
* Many methods below also have a variant which includes a `relation:` parameter to make the constraint an inequality.
|
||||
|
||||
### Attributes
|
||||
|
||||
PureLayout defines view attributes that are used to create auto layout constraints. Here is an [illustration of the most common attributes](Images/PureLayout-CommonAttributes.png).
|
||||
|
||||
There are 5 specific attribute types, which are used throughout most of the API:
|
||||
|
||||
* `ALEdge`
|
||||
* `ALDimension`
|
||||
* `ALAxis`
|
||||
* `ALMargin` *available in iOS 8.0 and higher only*
|
||||
* `ALMarginAxis` *available in iOS 8.0 and higher only*
|
||||
|
||||
Additionally, there is one generic attribute type, `ALAttribute`, which is effectively a union of all the specific types. You can think of this as the "supertype" of all of the specific attribute types, which means that it is always safe to cast a specific type to the generic `ALAttribute` type. (Note that the reverse is not true -- casting a generic ALAttribute to a specific attribute type is unsafe!)
|
||||
|
||||
### [`UIView`/`NSView`](PureLayout/PureLayout/ALView%2BPureLayout.h)
|
||||
```
|
||||
- autoSetContent(CompressionResistance|Hugging)PriorityForAxis:
|
||||
- autoCenterInSuperview(Margins): // Margins variant iOS 8.0+ only
|
||||
- autoAlignAxisToSuperview(Margin)Axis: // Margin variant iOS 8.0+ only
|
||||
- autoPinEdgeToSuperview(Edge:|Margin:)(withInset:) // Margin variant iOS 8.0+ only
|
||||
- autoPinEdgesToSuperview(Edges|Margins)(WithInsets:)(excludingEdge:) // Margins variant iOS 8.0+ only
|
||||
- autoPinEdge:toEdge:ofView:(withOffset:)
|
||||
- autoAlignAxis:toSameAxisOfView:(withOffset:|withMultiplier:)
|
||||
- autoMatchDimension:toDimension:ofView:(withOffset:|withMultiplier:)
|
||||
- autoSetDimension(s)ToSize:
|
||||
- autoConstrainAttribute:toAttribute:ofView:(withOffset:|withMultiplier:)
|
||||
- autoPinTo(Top|Bottom)LayoutGuideOfViewController:withInset: // iOS only
|
||||
```
|
||||
|
||||
### [`NSArray`](PureLayout/PureLayout/NSArray%2BPureLayout.h)
|
||||
```
|
||||
// Arrays of Constraints
|
||||
- autoInstallConstraints
|
||||
- autoRemoveConstraints
|
||||
- autoIdentifyConstraints: // iOS 7.0+, OS X 10.9+ only
|
||||
|
||||
// Arrays of Views
|
||||
- autoAlignViewsToEdge:
|
||||
- autoAlignViewsToAxis:
|
||||
- autoMatchViewsDimension:
|
||||
- autoSetViewsDimension:toSize:
|
||||
- autoSetViewsDimensionsToSize:
|
||||
- autoDistributeViewsAlongAxis:alignedTo:withFixedSpacing:(insetSpacing:)(matchedSizes:)
|
||||
- autoDistributeViewsAlongAxis:alignedTo:withFixedSize:(insetSpacing:)
|
||||
```
|
||||
|
||||
### [`NSLayoutConstraint`](PureLayout/PureLayout/NSLayoutConstraint%2BPureLayout.h)
|
||||
```
|
||||
+ autoCreateAndInstallConstraints:
|
||||
+ autoCreateConstraintsWithoutInstalling:
|
||||
+ autoSetPriority:forConstraints:
|
||||
+ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only
|
||||
- autoIdentify: // iOS 7.0+, OS X 10.9+ only
|
||||
- autoInstall
|
||||
- autoRemove
|
||||
```
|
||||
|
||||
## Usage
|
||||
### Sample Code (Swift)
|
||||
PureLayout dramatically simplifies writing Auto Layout code. Let's take a quick look at some examples, using PureLayout from Swift.
|
||||
|
||||
Here's a constraint between two views created (and automatically activated) using PureLayout:
|
||||
|
||||
```swift
|
||||
view1.autoPinEdge(.Top, toEdge: .Bottom, ofView: view2)
|
||||
```
|
||||
|
||||
Without PureLayout, here's the equivalent code you'd have to write using Apple's Foundation API directly:
|
||||
|
||||
```swift
|
||||
NSLayoutConstraint(item: view1, attribute: .Top, relatedBy: .Equal, toItem: view2, attribute: .Bottom, multiplier: 1.0, constant: 0.0).active = true
|
||||
```
|
||||
|
||||
Many APIs of PureLayout create multiple constraints for you under the hood, letting you write highly readable layout code:
|
||||
|
||||
```swift
|
||||
// 2 constraints created & activated in one line!
|
||||
logoImageView.autoCenterInSuperview()
|
||||
|
||||
// 4 constraints created & activated in one line!
|
||||
textContentView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 20.0, left: 5.0, bottom: 10.0, right: 5.0))
|
||||
```
|
||||
|
||||
PureLayout always returns the constraints it creates so you have full control:
|
||||
|
||||
```swift
|
||||
let constraint = skinnyView.autoMatchDimension(.Height, toDimension: .Width, ofView: tallView)
|
||||
```
|
||||
|
||||
PureLayout supports all Auto Layout features including inequalities, priorities, layout margins, identifiers, and much more. It's a comprehensive, developer-friendly way to use Auto Layout.
|
||||
|
||||
Check out the example apps below for many more demos of PureLayout in use.
|
||||
|
||||
### Example Apps
|
||||
Open the project included in the repository (requires Xcode 6 or higher). It contains [iOS](PureLayout/Example-iOS) (`Example-iOS` scheme) and [OS X](PureLayout/Example-Mac) (`Example-Mac` scheme) demos of the library being used in various scenarios. The demos in the iOS example app make a great introductory tutorial to PureLayout -- run each demo, review the code used to implement it, then practice by making some changes of your own to the demo code.
|
||||
|
||||
Each demo in the iOS example app has a Swift and Objective-C version. **To compile & run the Swift demos, you must use Xcode 7.0 or higher (Swift 2.0) and choose the `Example-iOS-Xcode7` scheme.** When you run the example app, you can easily switch between using the Swift and Objective-C versions of the demos. To see the constraints in action while running the iOS demos, try using different device simulators, rotating the device to different orientations, as well as toggling the taller in-call status bar in the iOS Simulator.
|
||||
|
||||
On OS X, while running the app, press any key to cycle through the demos. You can resize the window to see the constraints in action.
|
||||
|
||||
### Tips and Tricks
|
||||
Check out some [Tips and Tricks](https://github.com/PureLayout/PureLayout/wiki/Tips-and-Tricks) to keep in mind when using the API.
|
||||
|
||||
## PureLayout vs. the rest
|
||||
There are quite a few different ways to implement Auto Layout. Here is a quick overview of the available options:
|
||||
|
||||
* Apple [NSLayoutConstraint SDK API](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:)
|
||||
* Pros: Raw power
|
||||
* Cons: Extremely verbose; tedious to write; difficult to read
|
||||
* Apple [Visual Format Language](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html)
|
||||
* Pros: Concise; convenient
|
||||
* Cons: Doesn't support some use cases; lacks compile-time checking and safety; must learn syntax; hard to debug
|
||||
* Apple Interface Builder
|
||||
* Pros: Visual; interactive; provides compile-time layout checking
|
||||
* Cons: Difficult for complex layouts; cannot dynamically set constraints at runtime; encourages hardcoded magic numbers; not always WYSIWYG
|
||||
* Apple [NSLayoutAnchor SDK API](https://developer.apple.com/library/prerelease/ios/documentation/AppKit/Reference/NSLayoutAnchor_ClassReference/index.html)
|
||||
* Pros: Clean, readable, and type-safe API for creating individual constraints
|
||||
* Cons: Only available in iOS 9.0 and OS X 10.11 and higher; requires manually activating each constraint; no API for creating multiple constraints at once
|
||||
* **PureLayout**
|
||||
* Pros: Compatible with Objective-C and Swift codebases; consistent with Cocoa API style; cross-platform API and implementation shared across iOS and OS X; fully backwards-compatible to iOS 6 & OS X 10.7; easy to use; type-safe; efficient
|
||||
* Cons: Not the most concise expression of layout code
|
||||
* High-level Auto Layout Libraries/DSLs ([Cartography](https://github.com/robb/Cartography), [SnapKit](https://github.com/SnapKit/SnapKit), [KeepLayout](https://github.com/iMartinKiss/KeepLayout))
|
||||
* Pros: Very clean, concise, and convenient
|
||||
* Cons: Unique API style is foreign to Apple's APIs; mixed compatibility with Objective-C & Swift; greater dependency on third party code
|
||||
|
||||
PureLayout takes a balanced approach to Auto Layout that makes it well suited for any project.
|
||||
|
||||
## Problems, Suggestions, Pull Requests?
|
||||
Please open a [new Issue here](https://github.com/PureLayout/PureLayout/issues/new) if you run into a problem specific to PureLayout, have a feature request, or want to share a comment. Note that general Auto Layout questions should be asked on [Stack Overflow](http://stackoverflow.com).
|
||||
|
||||
Pull requests are encouraged and greatly appreciated! Please try to maintain consistency with the existing code style. If you're considering taking on significant changes or additions to the project, please communicate in advance by opening a new Issue. This allows everyone to get onboard with upcoming changes, ensures that changes align with the project's design philosophy, and avoids duplicated work.
|
||||
|
||||
## Meta
|
||||
Originally designed & built by Tyler Fox ([@smileyborg](https://github.com/smileyborg)). Currently maintained by Mickey Reiss ([@mickeyreiss](https://github.com/mickeyreiss)). Distributed with the MIT license.
|
||||
@ -140,6 +140,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
## PureLayout
|
||||
|
||||
This code is distributed under the terms and conditions of the MIT license.
|
||||
|
||||
Copyright (c) 2014-2015 Tyler Fox
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
## StrongestPasswordValidator
|
||||
|
||||
Copyright (c) 2016 Giuseppe Nucifora <me@giuseppenucifora.com>
|
||||
|
||||
@ -175,6 +175,23 @@ THE SOFTWARE.
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>This code is distributed under the terms and conditions of the MIT license.
|
||||
|
||||
Copyright (c) 2014-2015 Tyler Fox
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>PureLayout</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Copyright (c) 2016 Giuseppe Nucifora <me@giuseppenucifora.com>
|
||||
|
||||
@ -90,6 +90,7 @@ if [[ "$CONFIGURATION" == "Debug" ]]; then
|
||||
install_framework "Pods-PNObject_Example/NSString_Helper.framework"
|
||||
install_framework "Pods-PNObject_Example/PEAR_FileManager_iOS.framework"
|
||||
install_framework "Pods-PNObject_Example/PNObject.framework"
|
||||
install_framework "Pods-PNObject_Example/PureLayout.framework"
|
||||
install_framework "Pods-PNObject_Example/StrongestPasswordValidator.framework"
|
||||
install_framework "Pods-PNObject_Example/UIDevice_Utils.framework"
|
||||
install_framework "Pods-PNObject_Example/nv_ios_http_status.framework"
|
||||
@ -101,6 +102,7 @@ if [[ "$CONFIGURATION" == "Release" ]]; then
|
||||
install_framework "Pods-PNObject_Example/NSString_Helper.framework"
|
||||
install_framework "Pods-PNObject_Example/PEAR_FileManager_iOS.framework"
|
||||
install_framework "Pods-PNObject_Example/PNObject.framework"
|
||||
install_framework "Pods-PNObject_Example/PureLayout.framework"
|
||||
install_framework "Pods-PNObject_Example/StrongestPasswordValidator.framework"
|
||||
install_framework "Pods-PNObject_Example/UIDevice_Utils.framework"
|
||||
install_framework "Pods-PNObject_Example/nv_ios_http_status.framework"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
|
||||
OTHER_CFLAGS = $(inherited) -iquote "$CONFIGURATION_BUILD_DIR/AFNetworking.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/CodFis_Helper.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/NSDate_Utils.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/NSString_Helper.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PEAR_FileManager_iOS.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PNObject.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/StrongestPasswordValidator.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/UIDevice_Utils.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/nv_ios_http_status.framework/Headers"
|
||||
OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" -framework "CodFis_Helper" -framework "NSDate_Utils" -framework "NSString_Helper" -framework "PEAR_FileManager_iOS" -framework "PNObject" -framework "StrongestPasswordValidator" -framework "UIDevice_Utils" -framework "nv_ios_http_status"
|
||||
OTHER_CFLAGS = $(inherited) -iquote "$CONFIGURATION_BUILD_DIR/AFNetworking.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/CodFis_Helper.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/NSDate_Utils.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/NSString_Helper.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PEAR_FileManager_iOS.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PNObject.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PureLayout.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/StrongestPasswordValidator.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/UIDevice_Utils.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/nv_ios_http_status.framework/Headers"
|
||||
OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" -framework "CodFis_Helper" -framework "NSDate_Utils" -framework "NSString_Helper" -framework "PEAR_FileManager_iOS" -framework "PNObject" -framework "PureLayout" -framework "StrongestPasswordValidator" -framework "UIDevice_Utils" -framework "nv_ios_http_status"
|
||||
PODS_FRAMEWORK_BUILD_PATH = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-PNObject_Example"
|
||||
PODS_ROOT = ${SRCROOT}/Pods
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
|
||||
OTHER_CFLAGS = $(inherited) -iquote "$CONFIGURATION_BUILD_DIR/AFNetworking.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/CodFis_Helper.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/NSDate_Utils.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/NSString_Helper.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PEAR_FileManager_iOS.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PNObject.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/StrongestPasswordValidator.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/UIDevice_Utils.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/nv_ios_http_status.framework/Headers"
|
||||
OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" -framework "CodFis_Helper" -framework "NSDate_Utils" -framework "NSString_Helper" -framework "PEAR_FileManager_iOS" -framework "PNObject" -framework "StrongestPasswordValidator" -framework "UIDevice_Utils" -framework "nv_ios_http_status"
|
||||
OTHER_CFLAGS = $(inherited) -iquote "$CONFIGURATION_BUILD_DIR/AFNetworking.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/CodFis_Helper.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/NSDate_Utils.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/NSString_Helper.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PEAR_FileManager_iOS.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PNObject.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/PureLayout.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/StrongestPasswordValidator.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/UIDevice_Utils.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/nv_ios_http_status.framework/Headers"
|
||||
OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" -framework "CodFis_Helper" -framework "NSDate_Utils" -framework "NSString_Helper" -framework "PEAR_FileManager_iOS" -framework "PNObject" -framework "PureLayout" -framework "StrongestPasswordValidator" -framework "UIDevice_Utils" -framework "nv_ios_http_status"
|
||||
PODS_FRAMEWORK_BUILD_PATH = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-PNObject_Example"
|
||||
PODS_ROOT = ${SRCROOT}/Pods
|
||||
|
||||
26
Example/Pods/Target Support Files/PureLayout/Info.plist
generated
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>3.0.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
5
Example/Pods/Target Support Files/PureLayout/PureLayout-dummy.m
generated
Normal file
@ -0,0 +1,5 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
@interface PodsDummy_PureLayout : NSObject
|
||||
@end
|
||||
@implementation PodsDummy_PureLayout
|
||||
@end
|
||||
4
Example/Pods/Target Support Files/PureLayout/PureLayout-prefix.pch
generated
Normal file
@ -0,0 +1,4 @@
|
||||
#ifdef __OBJC__
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
12
Example/Pods/Target Support Files/PureLayout/PureLayout-umbrella.h
generated
Normal file
@ -0,0 +1,12 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "NSArray+PureLayout.h"
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
#import "PureLayout+Internal.h"
|
||||
#import "PureLayout.h"
|
||||
#import "PureLayoutDefines.h"
|
||||
|
||||
FOUNDATION_EXPORT double PureLayoutVersionNumber;
|
||||
FOUNDATION_EXPORT const unsigned char PureLayoutVersionString[];
|
||||
|
||||
6
Example/Pods/Target Support Files/PureLayout/PureLayout.modulemap
generated
Normal file
@ -0,0 +1,6 @@
|
||||
framework module PureLayout {
|
||||
umbrella header "PureLayout-umbrella.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
||||
5
Example/Pods/Target Support Files/PureLayout/PureLayout.xcconfig
generated
Normal file
@ -0,0 +1,5 @@
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public"
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
|
||||
SKIP_INSTALL = YES
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "PNObject"
|
||||
s.version = "0.3.2"
|
||||
s.version = "0.3.3"
|
||||
s.summary = "PNObject is a simple replica of the more complex ParseObject"
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
|
||||
@ -24,12 +24,34 @@
|
||||
* @return <#return value description#>
|
||||
*/
|
||||
- (BOOL) isValidPassword:(NSString* _Nonnull) password;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
- (void) logout;
|
||||
|
||||
- (BOOL) isValidUser;
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @return <#return value description#>
|
||||
*/
|
||||
- (BOOL) hasValidUserAndPasswordData;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @param success <#success description#>
|
||||
* @param failure <#failure description#>
|
||||
*/
|
||||
- (void) registerCurrentUserWithBlockSuccess:(nullable void (^)(id _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @return <#return value description#>
|
||||
*/
|
||||
- (BOOL) autenticated;
|
||||
|
||||
//- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id responseObject, NSError * error)) responseBlock;
|
||||
|
||||
@ -93,6 +115,10 @@
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong, nullable) NSString * password;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong, nullable) NSString * confirmPassword;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#import "NSString+Helper.h"
|
||||
#import "PNObjectConstants.h"
|
||||
#import "PNObject+Protected.h"
|
||||
#import "PNObject+PNObjectConnection.h"
|
||||
|
||||
|
||||
@interface PNUser() <PNObjectSubclassing>
|
||||
@ -90,6 +91,20 @@ static bool isFirstAccess = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setConfirmPassword:(NSString *)confirmPassword {
|
||||
if ([self isValidPassword:confirmPassword]) {
|
||||
if ([confirmPassword isEqualToString:_password]) {
|
||||
_confirmPassword = confirmPassword;
|
||||
}
|
||||
else {
|
||||
NSLogDebug(@"Inserted Passord is not same password.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLogDebug(@"Inserted Passord is not valid.Lenght must be >= %ld",(long)[[PNObjectConfig sharedInstance] minPasswordLenght]);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) isValidPassword:(NSString* _Nonnull) password {
|
||||
if ([password length] >= [[PNObjectConfig sharedInstance] minPasswordLenght]) {
|
||||
return YES;
|
||||
@ -102,7 +117,7 @@ static bool isFirstAccess = YES;
|
||||
[self resetObject];
|
||||
}
|
||||
|
||||
- (BOOL) isValidUser {
|
||||
- (BOOL) hasValidUserAndPasswordData {
|
||||
if(self.username && self.password && [self isValidPassword:[self password]]){
|
||||
return YES;
|
||||
}
|
||||
@ -110,6 +125,21 @@ static bool isFirstAccess = YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) registerCurrentUserWithBlockSuccess:(nullable void (^)(id _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSError * _Nonnull error))failure {
|
||||
|
||||
[self POSTWithEndpointAction:@"registration/register" Progress:nil success:^(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject) {
|
||||
NSLog(@"response %@",responseObject);
|
||||
if(success){
|
||||
success(responseObject);
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
if (failure) {
|
||||
failure(error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark PNObjectSubclassing Protocol
|
||||
|
||||
+ (NSDictionary *)objcetMapping {
|
||||
@ -122,7 +152,8 @@ static bool isFirstAccess = YES;
|
||||
@"sex":@"sex",
|
||||
@"birthDate":@"birthDate",
|
||||
@"phone":@"phone",
|
||||
@"password":@"password",
|
||||
@"password":@"plainPassword[first]",
|
||||
@"confirmPassword":@"plainPassword[second]",
|
||||
@"hasAcceptedPrivacy":@"hasAcceptedPrivacy",
|
||||
@"hasAcceptedNewsletter":@"hasAcceptedNewsletter",
|
||||
@"hasVerifiedEmail":@"hasVerifiedEmail",
|
||||
|
||||
@ -10,7 +10,21 @@
|
||||
|
||||
@interface PNObject (PNObjectConnection)
|
||||
|
||||
+ (NSURLSessionDataTask * _Nonnull) GETWithProgress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress
|
||||
+ (void) GETWithProgress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure;
|
||||
|
||||
+ (void) GETWithEndpointAction:(NSString * _Nonnull) endPoint
|
||||
Progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure;
|
||||
|
||||
+ (void) POSTWithProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure;
|
||||
|
||||
- (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint
|
||||
Progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure;
|
||||
|
||||
|
||||
@ -16,11 +16,16 @@
|
||||
|
||||
@implementation PNObject (PNObjectConnection)
|
||||
|
||||
+ (NSURLSessionDataTask * _Nonnull) GETWithProgress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress
|
||||
+ (void) GETWithProgress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
|
||||
|
||||
return [[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",[[self class] objectEndPoint]] parameters:nil progress:downloadProgress success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
if ([[PNObjectConfig sharedInstance] currentOauthCredential] && ![[[PNObjectConfig sharedInstance] currentOauthCredential] isExpired]) {
|
||||
|
||||
[[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",[[self class] objectEndPoint]]
|
||||
parameters:nil
|
||||
progress:downloadProgress
|
||||
success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
|
||||
id PNObjectResponse = [[[self class] alloc] initWithJSON:[responseObject copy]];
|
||||
|
||||
@ -33,8 +38,90 @@
|
||||
failure(task,error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
else {
|
||||
[[PNObjectConfig sharedInstance] refreshTokenForClientCredentialWithBlockSuccess:^(BOOL refreshSuccess) {
|
||||
|
||||
[self GETWithProgress:downloadProgress success:success failure:failure];
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void) GETWithEndpointAction:(NSString * _Nonnull) endPoint
|
||||
Progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
|
||||
|
||||
|
||||
if ([[PNObjectConfig sharedInstance] currentOauthCredential] && ![[[PNObjectConfig sharedInstance] currentOauthCredential] isExpired]) {
|
||||
|
||||
[[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:nil progress:downloadProgress success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
|
||||
id PNObjectResponse = [[[self class] alloc] initWithJSON:[responseObject copy]];
|
||||
|
||||
if (success) {
|
||||
success(task,PNObjectResponse);
|
||||
}
|
||||
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
if (failure) {
|
||||
failure(task,error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
else {
|
||||
[[PNObjectConfig sharedInstance] refreshTokenForClientCredentialWithBlockSuccess:^(BOOL refreshSuccess) {
|
||||
|
||||
[self GETWithProgress:downloadProgress success:success failure:failure];
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void) POSTWithProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint
|
||||
Progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
|
||||
|
||||
if ([[PNObjectConfig sharedInstance] currentOauthCredential] && ![[[PNObjectConfig sharedInstance] currentOauthCredential] isExpired]) {
|
||||
|
||||
[[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:[self JSONFormObject] progress:uploadProgress success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
|
||||
id PNObjectResponse = [[[self class] alloc] initWithJSON:[responseObject copy]];
|
||||
|
||||
if (success) {
|
||||
success(task,PNObjectResponse);
|
||||
}
|
||||
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
if (failure) {
|
||||
failure(task,error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
else {
|
||||
[[PNObjectConfig sharedInstance] refreshTokenForClientCredentialWithBlockSuccess:^(BOOL refreshSuccess) {
|
||||
|
||||
[self POSTWithEndpointAction:endPoint Progress:uploadProgress success:success failure:failure];
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
/*+ (nullable NSURLSessionDataTask *) POSTConstructingBodyWithBlock:(nullable void (^)(id <AFMultipartFormData> _Nonnull formData))block
|
||||
progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
||||
|
||||
@ -26,13 +26,6 @@
|
||||
{
|
||||
NSDictionary *properties = [PNObject propertiesForClass:self.class];
|
||||
|
||||
for (NSString *propertyName in properties) {
|
||||
if ([propertyName isEqualToString:@"description"] || [propertyName isEqualToString:@"debugDescription"]) {
|
||||
continue;
|
||||
}
|
||||
[self addObserver:self forKeyPath:propertyName options:NSKeyValueObservingOptionNew context:nil];
|
||||
}
|
||||
|
||||
for(NSString *propertyName in properties) {
|
||||
|
||||
if([propertyName isEqualToString:@"mappingError"])
|
||||
|
||||
@ -38,6 +38,8 @@
|
||||
|
||||
- (BOOL) autoRemoveLocally;
|
||||
|
||||
- (NSDictionary * _Nonnull) JSONFormObject;
|
||||
|
||||
///--------------------------------------
|
||||
#pragma mark - PNObject Properties
|
||||
///--------------------------------------
|
||||
@ -55,4 +57,5 @@
|
||||
*/
|
||||
@property (nonatomic, strong, nonnull) NSDictionary * JSONObject;
|
||||
|
||||
|
||||
@end
|
||||
@ -97,7 +97,17 @@
|
||||
_singleInstance = [[self class] singleInstance];
|
||||
|
||||
_createdAt = [[NSDate date] toLocalTime];
|
||||
}
|
||||
|
||||
_JSON = [[NSMutableDictionary alloc] init];
|
||||
|
||||
NSDictionary *properties = [PNObject propertiesForClass:self.class];
|
||||
|
||||
for (NSString *propertyName in properties) {
|
||||
if ([propertyName isEqualToString:@"description"] || [propertyName isEqualToString:@"debugDescription"]) {
|
||||
continue;
|
||||
}
|
||||
[self addObserver:self forKeyPath:propertyName options:NSKeyValueObservingOptionNew context:nil];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
@ -127,6 +137,15 @@
|
||||
|
||||
}
|
||||
|
||||
NSDictionary *properties = [PNObject propertiesForClass:self.class];
|
||||
|
||||
for (NSString *propertyName in properties) {
|
||||
if ([propertyName isEqualToString:@"description"] || [propertyName isEqualToString:@"debugDescription"]) {
|
||||
continue;
|
||||
}
|
||||
[self addObserver:self forKeyPath:propertyName options:NSKeyValueObservingOptionNew context:nil];
|
||||
}
|
||||
|
||||
NSAssert(_JSONObject, @"You must create objectMapping");
|
||||
_JSON = [[NSMutableDictionary alloc] initWithDictionary:JSON];
|
||||
|
||||
@ -274,6 +293,21 @@
|
||||
return _JSON;
|
||||
}
|
||||
|
||||
- (NSDictionary * _Nonnull) JSONFormObject {
|
||||
|
||||
NSMutableDictionary *JSONFormObject = [[NSMutableDictionary alloc] init];
|
||||
|
||||
NSDictionary *JSONMap = [[self class] objcetMapping];
|
||||
|
||||
for (NSString *key in JSONMap) {
|
||||
|
||||
if ([_JSON objectForKey:[JSONMap objectForKey:key]]) {
|
||||
[JSONFormObject setObject:[_JSON objectForKey:[JSONMap objectForKey:key]] forKey:[JSONMap objectForKey:key]];
|
||||
}
|
||||
}
|
||||
return JSONFormObject;
|
||||
}
|
||||
|
||||
|
||||
- (NSDictionary* _Nonnull) JSONObject {
|
||||
if (!_JSON) {
|
||||
@ -363,6 +397,7 @@
|
||||
_objID = nil;
|
||||
_createdAt = nil;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AFNetworking/AFNetworking.h>
|
||||
#import "HTTPStatusCodes.h"
|
||||
|
||||
#import "AFOAuth2Manager.h"
|
||||
#import "AFHTTPRequestSerializer+OAuth2.h"
|
||||
@ -112,6 +113,38 @@ extern NSString* _Nonnull const Client_Secret;
|
||||
*/
|
||||
- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
- (void) refreshTokenForClientCredential;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @param success <#success description#>
|
||||
* @param failure <#failure description#>
|
||||
*/
|
||||
- (void) refreshTokenForClientCredentialWithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
|
||||
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
- (void) refreshTokenForUser;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @param success <#success description#>
|
||||
* @param failure <#failure description#>
|
||||
*/
|
||||
- (void) refreshTokenForUserWithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
|
||||
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
- (BOOL) resetToken;
|
||||
|
||||
///--------------------------------------
|
||||
#pragma mark - PNObjectConfig Properties
|
||||
@ -119,7 +152,12 @@ extern NSString* _Nonnull const Client_Secret;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong) AFOAuth2Manager *manager;
|
||||
@property (nonatomic, strong, nonnull) AFOAuth2Manager *manager;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong, nullable, readonly) AFOAuthCredential *currentOauthCredential;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
|
||||
@ -35,8 +35,6 @@ NSString* const Client_Secret = @"client_secret";
|
||||
|
||||
@property (nonatomic) BOOL oauthEnabled;
|
||||
|
||||
@property (nonatomic, strong) AFOAuthCredential *currentOauthCredential;
|
||||
|
||||
@property (nonatomic, strong) NSMutableDictionary *configuration;
|
||||
@property (nonatomic, strong) NSMutableDictionary *headerFields;
|
||||
@property (nonatomic) Environment currentEnv;
|
||||
@ -193,6 +191,8 @@ static bool isFirstAccess = YES;
|
||||
_manager = [AFOAuth2Manager manager];
|
||||
}
|
||||
|
||||
_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
|
||||
if (_oauthEnabled && _currentOAuthClientID && _currentOAuthClientSecret) {
|
||||
|
||||
if (![_manager clientID]) {
|
||||
@ -211,38 +211,80 @@ static bool isFirstAccess = YES;
|
||||
|
||||
if (canTryRefreh) {
|
||||
|
||||
if (!_currentOauthCredential) {
|
||||
|
||||
[self tryRefreshToken];
|
||||
if (_currentOauthCredential && ![_currentOauthCredential isExpired]) {
|
||||
[[_manager requestSerializer] setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
}
|
||||
else {
|
||||
[[_manager requestSerializer] setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
[self refreshTokenForClientCredential];
|
||||
}
|
||||
}
|
||||
|
||||
return _manager;
|
||||
}
|
||||
|
||||
- (void) tryRefreshToken {
|
||||
if ([PNUser currentUser] && [[PNUser currentUser] isValidUser]) {
|
||||
- (BOOL) resetToken {
|
||||
if (_currentOauthCredential) {
|
||||
return [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) refreshTokenForUser {
|
||||
|
||||
[self refreshTokenForUserWithBlockSuccess:nil failure:nil];
|
||||
}
|
||||
|
||||
- (void) refreshTokenForUserWithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
|
||||
failure:(nullable void (^)(NSError * _Nonnull error))failure {
|
||||
|
||||
if([PNUser currentUser] && [[PNUser currentUser] hasValidUserAndPasswordData]) {
|
||||
[_manager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] username:[[PNUser currentUser] username] password:[[PNUser currentUser] password] scope:nil success:^(AFOAuthCredential * _Nonnull credential) {
|
||||
_currentOauthCredential = credential;
|
||||
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:error];
|
||||
}];
|
||||
}
|
||||
else {
|
||||
|
||||
[_manager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] scope:nil success:^(AFOAuthCredential * _Nonnull credential) {
|
||||
_currentOauthCredential = credential;
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
|
||||
if (success) {
|
||||
success(YES);
|
||||
}
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialFail object:error];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:error];
|
||||
if (failure) {
|
||||
failure(error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) refreshTokenForClientCredential {
|
||||
[self refreshTokenForClientCredentialWithBlockSuccess:nil failure:nil];
|
||||
}
|
||||
|
||||
|
||||
- (void) refreshTokenForClientCredentialWithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
|
||||
failure:(nullable void (^)(NSError * _Nonnull error))failure {
|
||||
|
||||
[_manager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] scope:nil success:^(AFOAuthCredential * _Nonnull credential) {
|
||||
_currentOauthCredential = credential;
|
||||
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
|
||||
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
|
||||
if (success) {
|
||||
success(YES);
|
||||
}
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialFail object:error];
|
||||
if (failure) {
|
||||
failure(error);
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght {
|
||||
_minPasswordLenght = passLenght;
|
||||
}
|
||||
|
||||