From f52b29826801b363fe76c19cc0b69344f790f961 Mon Sep 17 00:00:00 2001 From: Michael Pchelnikov Date: Sun, 12 Aug 2018 01:08:35 +0300 Subject: [PATCH] Fixed centering view --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++ MarkerKit/Info.plist | 2 +- README.md | 5 ++-- Sources/MarkerKit.swift | 13 +++------- iOS-Example/AppDelegate.swift | 26 ------------------- .../Base.lproj/LaunchScreen.storyboard | 16 ++++++++++-- iOS-Example/Info.plist | 2 +- iOS-Example/ViewController.swift | 7 +++++ 8 files changed, 38 insertions(+), 41 deletions(-) create mode 100644 MarkerKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/MarkerKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MarkerKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/MarkerKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/MarkerKit/Info.plist b/MarkerKit/Info.plist index 1007fd9..29dea2b 100644 --- a/MarkerKit/Info.plist +++ b/MarkerKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + 1.1 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/README.md b/README.md index d474dda..e213e6c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Lightweight and easy to use wrapper for Auto Layout Constraints (iOS 8+ support), inspired by [https://github.com/ustwo/autolayout-helper-swift](https://github.com/ustwo/autolayout-helper-swift) [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/pchelnikov/MarkerKit/blob/master/LICENSE) -[![Platform](https://img.shields.io/cocoapods/p/MarkerKit.svg?style=flat)](https://github.com/SnapKit/SnapKit) +[![Platform](https://img.shields.io/cocoapods/p/MarkerKit.svg?style=flat)](https://github.com/pchelnikov/MarkerKit) [![Cocoapods Compatible](https://img.shields.io/cocoapods/v/MarkerKit.svg)](https://cocoapods.org/pods/MarkerKit) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) @@ -147,8 +147,9 @@ UIView.animate(withDuration: 0.3) { ``` ## What to do next + * Writing tests ## License -Device is available under the MIT license. See the LICENSE file for more info. +MarkerKit is available under the MIT license. See the LICENSE file for more info. diff --git a/Sources/MarkerKit.swift b/Sources/MarkerKit.swift index 0ea6064..ecdee4a 100644 --- a/Sources/MarkerKit.swift +++ b/Sources/MarkerKit.swift @@ -115,15 +115,10 @@ public struct MarkerConstraintView { @discardableResult public func center(to view: Any?) -> [NSLayoutConstraint] { - var constraints: [NSLayoutConstraint] = [] - - if let superview = self.view.superview { - let centerXConstraint = centerX(to: superview) - let centerYConstraint = centerY(to: superview) - - constraints = [centerXConstraint, centerYConstraint] - } - + let centerXConstraint = centerX(to: view) + let centerYConstraint = centerY(to: view) + let constraints = [centerXConstraint, centerYConstraint] + return constraints } diff --git a/iOS-Example/AppDelegate.swift b/iOS-Example/AppDelegate.swift index 06e2c92..3ed677a 100644 --- a/iOS-Example/AppDelegate.swift +++ b/iOS-Example/AppDelegate.swift @@ -13,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { window = UIWindow(frame: UIScreen.main.bounds) @@ -25,29 +24,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return true } - - func applicationWillResignActive(_ application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. - } - - func applicationDidEnterBackground(_ application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } - - func applicationWillEnterForeground(_ application: UIApplication) { - // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. - } - - func applicationDidBecomeActive(_ application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - } - - func applicationWillTerminate(_ application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - - } - diff --git a/iOS-Example/Base.lproj/LaunchScreen.storyboard b/iOS-Example/Base.lproj/LaunchScreen.storyboard index 2859b4f..bfba870 100644 --- a/iOS-Example/Base.lproj/LaunchScreen.storyboard +++ b/iOS-Example/Base.lproj/LaunchScreen.storyboard @@ -1,11 +1,11 @@ - + - + @@ -20,7 +20,19 @@ + + + + + + + diff --git a/iOS-Example/Info.plist b/iOS-Example/Info.plist index 4222ac2..d155d57 100644 --- a/iOS-Example/Info.plist +++ b/iOS-Example/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.1 CFBundleVersion 1 LSRequiresIPhoneOS diff --git a/iOS-Example/ViewController.swift b/iOS-Example/ViewController.swift index 635ab39..58bc61e 100644 --- a/iOS-Example/ViewController.swift +++ b/iOS-Example/ViewController.swift @@ -13,6 +13,7 @@ class ViewController: UIViewController { private let leftTopView = UIView() private let rightBottomView = UIView() private let centerView = UIView() + private let subCenterView = UIView() private let secondCenterView = UIView() override func viewDidLoad() { @@ -28,11 +29,13 @@ class ViewController: UIViewController { leftTopView.backgroundColor = UIColor.blue.withAlphaComponent(0.5) rightBottomView.backgroundColor = UIColor.green.withAlphaComponent(0.5) centerView.backgroundColor = UIColor.red.withAlphaComponent(0.5) + subCenterView.backgroundColor = UIColor.black.withAlphaComponent(0.5) secondCenterView.backgroundColor = UIColor.yellow.withAlphaComponent(0.5) view.addSubview(leftTopView) view.addSubview(rightBottomView) view.addSubview(centerView) + view.addSubview(subCenterView) view.addSubview(secondCenterView) } @@ -55,5 +58,9 @@ class ViewController: UIViewController { secondCenterView.mrk.leading(to: centerView, attribute: .centerX, relation: .equal, constant: 0) secondCenterView.mrk.width(100) secondCenterView.mrk.height(70) + + subCenterView.mrk.center(to: secondCenterView) + subCenterView.mrk.width(30) + subCenterView.mrk.height(30) } }