diff --git a/ImagePickerSheetController/Example/AppDelegate.swift b/ImagePickerSheetController/Example/AppDelegate.swift index 8853615..970aa91 100644 --- a/ImagePickerSheetController/Example/AppDelegate.swift +++ b/ImagePickerSheetController/Example/AppDelegate.swift @@ -18,7 +18,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return window }() - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { window?.rootViewController = ViewController() window?.makeKeyAndVisible() diff --git a/ImagePickerSheetController/Example/ViewController.swift b/ImagePickerSheetController/Example/ViewController.swift index 3963da8..590ee6e 100644 --- a/ImagePickerSheetController/Example/ViewController.swift +++ b/ImagePickerSheetController/Example/ViewController.swift @@ -18,7 +18,7 @@ class ViewController: UIViewController { super.viewDidLoad() let button = UIButton(type: .system) - button.setTitle("Tap Me!", for: UIControlState()) + button.setTitle("Tap Me!", for: UIControl.State()) button.translatesAutoresizingMaskIntoConstraints = false view.addSubview(button) button.heightAnchor.constraint(equalToConstant: 40).isActive = true @@ -32,7 +32,7 @@ class ViewController: UIViewController { @objc func presentImagePickerSheet(_ gestureRecognizer: UITapGestureRecognizer) { - let presentImagePickerController: (UIImagePickerControllerSourceType) -> () = { source in + let presentImagePickerController: (UIImagePickerController.SourceType) -> () = { source in let controller = UIImagePickerController() controller.delegate = self var sourceType = source diff --git a/ImagePickerSheetController/ImagePickerSheetController.xcodeproj/project.pbxproj b/ImagePickerSheetController/ImagePickerSheetController.xcodeproj/project.pbxproj index 41433f8..3b6c570 100644 --- a/ImagePickerSheetController/ImagePickerSheetController.xcodeproj/project.pbxproj +++ b/ImagePickerSheetController/ImagePickerSheetController.xcodeproj/project.pbxproj @@ -374,17 +374,17 @@ TargetAttributes = { 49DC4A501B14F1BC00B4E78E = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1000; }; 49DC4A5B1B14F1BC00B4E78E = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0900; + LastSwiftMigration = ""; TestTargetID = 49DC4A851B14F31500B4E78E; }; 49DC4A851B14F31500B4E78E = { CreatedOnToolsVersion = 6.3.1; DevelopmentTeam = 5953RHWYWT; - LastSwiftMigration = 0900; + LastSwiftMigration = 1000; }; }; }; @@ -638,8 +638,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "ch.laurinbrandner.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -659,8 +658,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "ch.laurinbrandner.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -718,8 +716,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "ch.laurinbrandner.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -735,8 +732,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "ch.laurinbrandner.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/ImagePickerSheetController/ImagePickerSheetController/ImagePickerSheetController.swift b/ImagePickerSheetController/ImagePickerSheetController/ImagePickerSheetController.swift index e37a7ff..ab6b3e9 100644 --- a/ImagePickerSheetController/ImagePickerSheetController/ImagePickerSheetController.swift +++ b/ImagePickerSheetController/ImagePickerSheetController/ImagePickerSheetController.swift @@ -63,7 +63,7 @@ open class ImagePickerSheetController: UIViewController { collectionView.showsHorizontalScrollIndicator = false collectionView.alwaysBounceHorizontal = true collectionView.register(PreviewCollectionViewCell.self, forCellWithReuseIdentifier: NSStringFromClass(PreviewCollectionViewCell.self)) - collectionView.register(PreviewSupplementaryView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: NSStringFromClass(PreviewSupplementaryView.self)) + collectionView.register(PreviewSupplementaryView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: NSStringFromClass(PreviewSupplementaryView.self)) return collectionView }() @@ -144,11 +144,11 @@ open class ImagePickerSheetController: UIViewController { modalPresentationStyle = .custom transitioningDelegate = self - NotificationCenter.default.addObserver(sheetController, selector: #selector(SheetController.handleCancelAction), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil) + NotificationCenter.default.addObserver(sheetController, selector: #selector(SheetController.handleCancelAction), name: UIApplication.didEnterBackgroundNotification, object: nil) } deinit { - NotificationCenter.default.removeObserver(sheetController, name: .UIApplicationDidEnterBackground, object: nil) + NotificationCenter.default.removeObserver(sheetController, name: UIApplication.didEnterBackgroundNotification, object: nil) } // MARK: - View Lifecycle @@ -202,6 +202,12 @@ open class ImagePickerSheetController: UIViewController { open func addAction(_ action: ImagePickerAction) { sheetController.addAction(action) view.setNeedsLayout() + + // Explicitly disable animations + CATransaction.begin() + CATransaction.setDisableActions(true) + self.view.layoutIfNeeded() + CATransaction.commit() } // MARK: - Images @@ -424,9 +430,9 @@ extension ImagePickerSheetController: UICollectionViewDataSource { public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { - let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: NSStringFromClass(PreviewSupplementaryView.self), for: indexPath) as! PreviewSupplementaryView + let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: NSStringFromClass(PreviewSupplementaryView.self), for: indexPath) as! PreviewSupplementaryView view.isUserInteractionEnabled = false - view.buttonInset = UIEdgeInsetsMake(0.0, previewCheckmarkInset, previewCheckmarkInset, 0.0) + view.buttonInset = UIEdgeInsets.init(top: 0.0, left: previewCheckmarkInset, bottom: previewCheckmarkInset, right: 0.0) view.selected = selectedAssetIndices.contains(indexPath.section) supplementaryViews[indexPath.section] = view diff --git a/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionView.swift b/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionView.swift index c02a2ca..6bad5e0 100644 --- a/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionView.swift +++ b/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionView.swift @@ -47,7 +47,7 @@ class PreviewCollectionView: UICollectionView { if !bouncing { let possibleIndexPath = indexPathForItem(at: gestureRecognizer.location(in: self)) if let indexPath = possibleIndexPath { - selectItem(at: indexPath, animated: false, scrollPosition: UICollectionViewScrollPosition()) + selectItem(at: indexPath, animated: false, scrollPosition: UICollectionView.ScrollPosition()) delegate?.collectionView?(self, didSelectItemAt: indexPath) } } diff --git a/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionViewLayout.swift b/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionViewLayout.swift index 931d3e6..a324438 100644 --- a/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionViewLayout.swift +++ b/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionViewLayout.swift @@ -100,7 +100,7 @@ class PreviewCollectionViewLayout: UICollectionViewFlowLayout { return layoutAttributes .filter { rect.intersects($0.frame) } .reduce([UICollectionViewLayoutAttributes]()) { memo, attributes in - if let supplementaryAttributes = layoutAttributesForSupplementaryView(ofKind: UICollectionElementKindSectionHeader, at: attributes.indexPath) { + if let supplementaryAttributes = layoutAttributesForSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, at: attributes.indexPath) { return memo + [attributes, supplementaryAttributes] } return memo diff --git a/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewSupplementaryView.swift b/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewSupplementaryView.swift index f36f5d4..db45e3d 100644 --- a/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewSupplementaryView.swift +++ b/ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewSupplementaryView.swift @@ -14,7 +14,7 @@ class PreviewSupplementaryView: UICollectionReusableView { let button = UIButton() button.tintColor = .white button.isUserInteractionEnabled = false - button.setImage(PreviewSupplementaryView.checkmarkImage, for: UIControlState()) + button.setImage(PreviewSupplementaryView.checkmarkImage, for: UIControl.State()) button.setImage(PreviewSupplementaryView.selectedCheckmarkImage, for: .selected) return button diff --git a/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetActionCollectionViewCell.swift b/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetActionCollectionViewCell.swift index c8aee69..7aa6af5 100644 --- a/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetActionCollectionViewCell.swift +++ b/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetActionCollectionViewCell.swift @@ -64,7 +64,7 @@ class SheetActionCollectionViewCell: SheetCollectionViewCell { override func layoutSubviews() { super.layoutSubviews() - textLabel.frame = UIEdgeInsetsInsetRect(bounds, backgroundInsets) + textLabel.frame = bounds.inset(by: backgroundInsets) } } diff --git a/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetCollectionViewCell.swift b/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetCollectionViewCell.swift index f9e160d..38b0486 100644 --- a/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetCollectionViewCell.swift +++ b/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetCollectionViewCell.swift @@ -122,7 +122,7 @@ class SheetCollectionViewCell: UICollectionViewCell { let layerMask = layer.mask as? CAShapeLayer layerMask?.frame = bounds - layerMask?.path = maskPathWithRect(UIEdgeInsetsInsetRect(bounds, backgroundInsets), roundedCorner: roundedCorners) + layerMask?.path = maskPathWithRect(bounds.inset(by: backgroundInsets), roundedCorner: roundedCorners) } fileprivate func maskPathWithRect(_ rect: CGRect, roundedCorner: RoundedCorner) -> CGPath { diff --git a/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetPreviewCollectionViewCell.swift b/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetPreviewCollectionViewCell.swift index e097eb1..839ea59 100644 --- a/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetPreviewCollectionViewCell.swift +++ b/ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetPreviewCollectionViewCell.swift @@ -33,7 +33,7 @@ class SheetPreviewCollectionViewCell: SheetCollectionViewCell { override func layoutSubviews() { super.layoutSubviews() - collectionView?.frame = UIEdgeInsetsInsetRect(bounds, backgroundInsets) + collectionView?.frame = bounds.inset(by: backgroundInsets) } }