diff --git a/README.md b/README.md index 9fbaeaa..beb4e43 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ tabPageViewController.isInfinity = true ## Requirements -iOS8+ +iOS9+ ## Installation diff --git a/Sources/TabPageViewController.swift b/Sources/TabPageViewController.swift index 2bcabc1..6a6b2a3 100644 --- a/Sources/TabPageViewController.swift +++ b/Sources/TabPageViewController.swift @@ -137,43 +137,16 @@ extension TabPageViewController { fileprivate func configuredTabView() -> TabView { let tabView = TabView(isInfinity: isInfinity, option: option) - tabView.translatesAutoresizingMaskIntoConstraints = false - - let height = NSLayoutConstraint(item: tabView, - attribute: .height, - relatedBy: .equal, - toItem: nil, - attribute: .height, - multiplier: 1.0, - constant: option.tabHeight) - tabView.addConstraint(height) view.addSubview(tabView) - let top = NSLayoutConstraint(item: tabView, - attribute: .top, - relatedBy: .equal, - toItem: topLayoutGuide, - attribute: .bottom, - multiplier:1.0, - constant: 0.0) - - let left = NSLayoutConstraint(item: tabView, - attribute: .leading, - relatedBy: .equal, - toItem: view, - attribute: .leading, - multiplier: 1.0, - constant: 0.0) - - let right = NSLayoutConstraint(item: view, - attribute: .trailing, - relatedBy: .equal, - toItem: tabView, - attribute: .trailing, - multiplier: 1.0, - constant: 0.0) - - view.addConstraints([top, left, right]) + tabView.translatesAutoresizingMaskIntoConstraints = false + tabBarTopConstraint = tabView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor) + NSLayoutConstraint.activate([ + tabView.heightAnchor.constraint(equalToConstant: option.tabHeight), + tabBarTopConstraint!, + tabView.leadingAnchor.constraint(equalTo: view.leadingAnchor), + tabView.trailingAnchor.constraint(equalTo: view.trailingAnchor) + ]) tabView.pageTabItems = tabItems.map({ $0.title}) tabView.updateCurrentIndex(beforeIndex, shouldScroll: true) @@ -182,52 +155,23 @@ extension TabPageViewController { self?.displayControllerWithIndex(index, direction: direction, animated: true) } - tabBarTopConstraint = top - return tabView } private func setupStatusView() { let statusView = UIView() statusView.backgroundColor = option.tabBackgroundColor - statusView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(statusView) - let top = NSLayoutConstraint(item: statusView, - attribute: .top, - relatedBy: .equal, - toItem: view, - attribute: .top, - multiplier:1.0, - constant: 0.0) - - let left = NSLayoutConstraint(item: statusView, - attribute: .leading, - relatedBy: .equal, - toItem: view, - attribute: .leading, - multiplier: 1.0, - constant: 0.0) - - let right = NSLayoutConstraint(item: view, - attribute: .trailing, - relatedBy: .equal, - toItem: statusView, - attribute: .trailing, - multiplier: 1.0, - constant: 0.0) - - let height = NSLayoutConstraint(item: statusView, - attribute: .height, - relatedBy: .equal, - toItem: nil, - attribute: .height, - multiplier: 1.0, - constant: topLayoutGuide.length) - - view.addConstraints([top, left, right, height]) - - statusViewHeightConstraint = height + statusView.translatesAutoresizingMaskIntoConstraints = false + statusViewHeightConstraint = statusView.heightAnchor.constraint(equalToConstant: topLayoutGuide.length) + NSLayoutConstraint.activate([ + statusView.topAnchor.constraint(equalTo: view.topAnchor), + statusView.leadingAnchor.constraint(equalTo: view.leadingAnchor), + statusView.trailingAnchor.constraint(equalTo: view.trailingAnchor), + statusViewHeightConstraint! + ]) + self.statusView = statusView } diff --git a/Sources/TabView.swift b/Sources/TabView.swift index 0a870b7..57fd744 100644 --- a/Sources/TabView.swift +++ b/Sources/TabView.swift @@ -47,40 +47,13 @@ internal class TabView: UIView { addSubview(contentView) contentView.backgroundColor = option.tabBackgroundColor.withAlphaComponent(option.tabBarAlpha) - let top = NSLayoutConstraint(item: contentView, - attribute: .top, - relatedBy: .equal, - toItem: self, - attribute: .top, - multiplier: 1.0, - constant: 0.0) - - let left = NSLayoutConstraint(item: contentView, - attribute: .leading, - relatedBy: .equal, - toItem: self, - attribute: .leading, - multiplier: 1.0, - constant: 0.0) - - let bottom = NSLayoutConstraint (item: self, - attribute: .bottom, - relatedBy: .equal, - toItem: contentView, - attribute: .bottom, - multiplier: 1.0, - constant: 0.0) - - let right = NSLayoutConstraint(item: self, - attribute: .trailing, - relatedBy: .equal, - toItem: contentView, - attribute: .trailing, - multiplier: 1.0, - constant: 0.0) - contentView.translatesAutoresizingMaskIntoConstraints = false - self.addConstraints([top, left, bottom, right]) + NSLayoutConstraint.activate([ + contentView.topAnchor.constraint(equalTo: topAnchor), + contentView.leadingAnchor.constraint(equalTo: leadingAnchor), + contentView.bottomAnchor.constraint(equalTo: bottomAnchor), + contentView.trailingAnchor.constraint(equalTo: trailingAnchor) + ]) let bundle = Bundle(for: TabView.self) let nib = UINib(nibName: TabCollectionCell.cellIdentifier(), bundle: bundle) @@ -95,23 +68,13 @@ internal class TabView: UIView { currentBarView.removeFromSuperview() collectionView.addSubview(currentBarView) currentBarView.translatesAutoresizingMaskIntoConstraints = false - let top = NSLayoutConstraint(item: currentBarView, - attribute: .top, - relatedBy: .equal, - toItem: collectionView, - attribute: .top, - multiplier: 1.0, - constant: option.tabHeight - currentBarViewHeightConstraint.constant) - - let left = NSLayoutConstraint(item: currentBarView, - attribute: .leading, - relatedBy: .equal, - toItem: collectionView, - attribute: .leading, - multiplier: 1.0, - constant: 0.0) - currentBarViewLeftConstraint = left - collectionView.addConstraints([top, left]) + currentBarViewLeftConstraint = currentBarView.leadingAnchor.constraint(equalTo: collectionView.leadingAnchor) + NSLayoutConstraint.activate([ + currentBarView.topAnchor.constraint( + equalTo: collectionView.topAnchor, + constant: option.tabHeight - currentBarViewHeightConstraint.constant), + currentBarViewLeftConstraint! + ]) } bottomBarViewHeightConstraint.constant = 1.0 / UIScreen.main.scale diff --git a/TabPageViewController.podspec b/TabPageViewController.podspec index 962b556..7308298 100644 --- a/TabPageViewController.podspec +++ b/TabPageViewController.podspec @@ -25,7 +25,7 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/EndouMari/TabPageViewController.git", :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/' - s.platform = :ios, '8.0' + s.platform = :ios, '9.0' s.requires_arc = true s.source_files = 'Sources/*.swift' diff --git a/TabPageViewController.xcodeproj/project.pbxproj b/TabPageViewController.xcodeproj/project.pbxproj index a8b687f..0da93c3 100644 --- a/TabPageViewController.xcodeproj/project.pbxproj +++ b/TabPageViewController.xcodeproj/project.pbxproj @@ -418,7 +418,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = Demo/TabPageViewControllerDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.TabPageViewControllerDemo; @@ -464,7 +464,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = Demo/TabPageViewControllerDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.TabPageViewControllerDemo; @@ -487,7 +487,7 @@ ); HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = TabPageViewController.xcodeproj/TabPageViewController_Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; @@ -511,7 +511,7 @@ ); HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = TabPageViewController.xcodeproj/TabPageViewController_Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; @@ -567,7 +567,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_NS_ASSERTIONS = YES; GCC_OPTIMIZATION_LEVEL = 0; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; ONLY_ACTIVE_ARCH = YES; OTHER_SWIFT_FLAGS = "-DXcode"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -589,7 +589,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_OPTIMIZATION_LEVEL = s; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; OTHER_SWIFT_FLAGS = "-DXcode"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos;