diff --git a/PhotoSliderDemo/ViewController.swift b/PhotoSliderDemo/ViewController.swift index cccbf4b..98d9a78 100644 --- a/PhotoSliderDemo/ViewController.swift +++ b/PhotoSliderDemo/ViewController.swift @@ -74,9 +74,8 @@ class ViewController: UIViewController { } var width = view.bounds.width - if #available(iOS 11.0, *) { - width = view.bounds.width - view.safeAreaInsets.left - view.safeAreaInsets.right - } + width = view.bounds.width - view.safeAreaInsets.left - view.safeAreaInsets.right + collectionView.contentOffset = CGPoint(x: CGFloat(currentRow) * width, y: 0.0) } @@ -153,18 +152,10 @@ extension ViewController: UICollectionViewDelegateFlowLayout { } else { let height: CGFloat - if #available(iOS 11.0, *) { - height = view.safeAreaLayoutGuide.layoutFrame.height - } else { - height = view.bounds.height - } - + height = view.safeAreaLayoutGuide.layoutFrame.height return CGSize(width: tableView.bounds.width, height: height) - } - } - } // MARK: - UITableViewDataSource @@ -236,12 +227,11 @@ extension ViewController: ZoomingAnimationControllerTransitioning { var frame = cell.imageView.frame frame.origin.y += UIApplication.shared.statusBarFrame.height // tune in UIImageView - if #available(iOS 11.0, *) { - frame.origin.x = view.safeAreaInsets.left - if view.bounds.width > view.bounds.height { - frame.size.height = view.safeAreaLayoutGuide.layoutFrame.height - } + frame.origin.x = view.safeAreaInsets.left + if view.bounds.width > view.bounds.height { + frame.size.height = view.safeAreaLayoutGuide.layoutFrame.height } + imageView.frame = frame imageView.clipsToBounds = true imageView.contentMode = .scaleAspectFill @@ -274,32 +264,17 @@ extension ViewController: ZoomingAnimationControllerTransitioning { } else { let width: CGFloat let x: CGFloat - if #available(iOS 11.0, *) { - width = view.bounds.width - view.safeAreaInsets.left - view.safeAreaInsets.right - x = view.safeAreaInsets.left - } else { - width = view.bounds.width - x = 0 - } + width = view.bounds.width - view.safeAreaInsets.left - view.safeAreaInsets.right + x = view.safeAreaInsets.left let height: CGFloat - if #available(iOS 11.0, *) { - height = view.safeAreaLayoutGuide.layoutFrame.height - } else { - height = (image.size.height * width) / image.size.width - } + height = view.safeAreaLayoutGuide.layoutFrame.height let y: CGFloat - if #available(iOS 11.0, *) { - y = (height - view.safeAreaLayoutGuide.layoutFrame.height - statusBarHeight) * 0.5 - } else { - y = (height - UIScreen.main.bounds.height - statusBarHeight) * 0.5 - } - + y = (height - view.safeAreaLayoutGuide.layoutFrame.height - statusBarHeight) * 0.5 frame = CGRect(x: x, y: -1.0 * y, width: width, height: height) } sourceImageView.frame = frame - } } diff --git a/Sources/PhotoSlider/Classes/ImageView.swift b/Sources/PhotoSlider/Classes/ImageView.swift index 355ee64..e26a40d 100644 --- a/Sources/PhotoSlider/Classes/ImageView.swift +++ b/Sources/PhotoSlider/Classes/ImageView.swift @@ -44,9 +44,8 @@ class ImageView: UIView { scrollView.maximumZoomScale = 3.0 scrollView.delegate = self scrollView.alwaysBounceVertical = true - if #available(iOS 11.0, *) { - scrollView.contentInsetAdjustmentBehavior = .never - } + scrollView.contentInsetAdjustmentBehavior = .never + // image imageView = UIImageView(frame: CGRect.zero) imageView.contentMode = .scaleAspectFit diff --git a/Sources/PhotoSlider/Classes/ViewController.swift b/Sources/PhotoSlider/Classes/ViewController.swift index fa0e116..df5a4ae 100644 --- a/Sources/PhotoSlider/Classes/ViewController.swift +++ b/Sources/PhotoSlider/Classes/ViewController.swift @@ -41,10 +41,7 @@ public class ViewController: UIViewController { height: self.view.bounds.height * 3.0 ) - if #available(iOS 11.0, *) { - scrollView.contentInsetAdjustmentBehavior = .never - } - + scrollView.contentInsetAdjustmentBehavior = .never return scrollView }() @@ -64,7 +61,7 @@ public class ViewController: UIViewController { if let captionHeight = captionHeight { var y = view.bounds.height - captionHeight - 32.0 var height = captionHeight + 32.0 - if #available(iOS 11.0, *), let window = UIApplication.shared.keyWindow { + if let window = UIApplication.shared.keyWindow { let bottomSafeInsetSpacing = window.safeAreaInsets.bottom height += bottomSafeInsetSpacing y -= bottomSafeInsetSpacing @@ -309,61 +306,32 @@ fileprivate extension ViewController { func layoutCloseButton() { closeButton.translatesAutoresizingMaskIntoConstraints = false - if #available(iOS 11.0, *) { - [ - closeButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0.0), - closeButton.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: 0.0), - closeButton.heightAnchor.constraint(equalToConstant: 52.0), - closeButton.widthAnchor.constraint(equalToConstant: 52.0), - ].forEach { $0.isActive = true } - } else { - [ - closeButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0), - closeButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0.0), - closeButton.heightAnchor.constraint(equalToConstant: 52.0), - closeButton.widthAnchor.constraint(equalToConstant: 52.0), - ].forEach { $0.isActive = true } - - } + [ + closeButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0.0), + closeButton.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: 0.0), + closeButton.heightAnchor.constraint(equalToConstant: 52.0), + closeButton.widthAnchor.constraint(equalToConstant: 52.0), + ].forEach { $0.isActive = true } } func layoutShareButton() { shareButton.translatesAutoresizingMaskIntoConstraints = false - if #available(iOS 11.0, *) { - [ - shareButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0.0), - shareButton.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 0.0), - shareButton.heightAnchor.constraint(equalToConstant: 52.0), - shareButton.widthAnchor.constraint(equalToConstant: 52.0), - ].forEach { $0.isActive = true } - } else { - [ - shareButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0), - shareButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0.0), - shareButton.heightAnchor.constraint(equalToConstant: 52.0), - shareButton.widthAnchor.constraint(equalToConstant: 52.0), - ].forEach { $0.isActive = true } - - } + [ + shareButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0.0), + shareButton.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 0.0), + shareButton.heightAnchor.constraint(equalToConstant: 52.0), + shareButton.widthAnchor.constraint(equalToConstant: 52.0), + ].forEach { $0.isActive = true } } - + func layoutPageControl() { pageControl.translatesAutoresizingMaskIntoConstraints = false - if #available(iOS 11.0, *) { - [ - pageControl.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: 0.0), - pageControl.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), - pageControl.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: 0.0), - pageControl.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 0.0), - ].forEach { $0.isActive = true } - } else { - [ - pageControl.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0), - pageControl.centerXAnchor.constraint(equalTo: view.centerXAnchor), - pageControl.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0.0), - pageControl.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0.0), - ].forEach { $0.isActive = true } - } + [ + pageControl.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: 0.0), + pageControl.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), + pageControl.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: 0.0), + pageControl.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 0.0), + ].forEach { $0.isActive = true } } func layoutCaptionLabel() { @@ -379,19 +347,10 @@ fileprivate extension ViewController { } captionLabel.translatesAutoresizingMaskIntoConstraints = false - if #available(iOS 11.0, *) { - [ - captionLabel.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -32.0), - captionLabel.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: -16.0), - captionLabel.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 16.0), - ].forEach { $0.isActive = true } - } else { - [ - captionLabel.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -32.0), - captionLabel.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -16.0), - captionLabel.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 16.0), - ].forEach { $0.isActive = true } - } + [ captionLabel.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -32.0), + captionLabel.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: -16.0), + captionLabel.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 16.0), + ].forEach { $0.isActive = true } if let captionHeight = captionHeight { captionLabel.heightAnchor.constraint(equalToConstant: captionHeight).isActive = true