Skip to content

Commit

Permalink
fixes for iOS 13 and iOS 14 include fixes for landscape orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo committed Nov 13, 2020
1 parent ab3cf72 commit 767935a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DPPickerManager.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "DPPickerManager"
s.version = "1.0.2"
s.version = "1.0.3"
s.summary = "UIPicker inside a UIAlertController."

s.homepage = "https://github.com/priore/DPPickerManager"
Expand Down
29 changes: 24 additions & 5 deletions DPPickerManager/Class/DPPickerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ open class DPPickerManager: NSObject, UIPickerViewDelegate, UIPickerViewDataSour
picker.maximumDate = max
picker.timeZone = self.timeZone
picker.datePickerMode = .date
if #available(iOS 13.4, *) {
picker.preferredDatePickerStyle = .wheels
}
}, completion: completion)
}

@objc open func showPicker(title: String?, picker:((_ picker: UIDatePicker) -> Void)?, completion:DPPickerDateCompletion?) {
let datePicker = UIDatePicker()
datePicker.timeZone = self.timeZone

if #available(iOS 13.4, *) {
datePicker.preferredDatePickerStyle = .wheels
}

picker?(datePicker)

self.showPicker(title: title, view: datePicker) { (cancel) in
Expand Down Expand Up @@ -95,9 +101,10 @@ open class DPPickerManager: NSObject, UIPickerViewDelegate, UIPickerViewDataSour
var buttonX: CGFloat = 0

let image = UIImage(named: "ic_close")?.withRenderingMode(.alwaysTemplate)

view.translatesAutoresizingMaskIntoConstraints = false

// trick
let alertView = UIAlertController(title: title, message: "\n\n\n\n\n\n\n\n\n\n", preferredStyle: .actionSheet);
let alertView = UIAlertController(title: title, message: "\n\n\n\n\n\n\n\n\n\n", preferredStyle: .actionSheet)
alertView.view.addSubview(view)
alertView.popoverPresentationController?.sourceView = UIViewController.top?.view
alertView.popoverPresentationController?.sourceRect = view.bounds
Expand All @@ -116,17 +123,29 @@ open class DPPickerManager: NSObject, UIPickerViewDelegate, UIPickerViewDataSour
}

view.center.x = center ?? 0
view.transform = .init(translationX: -10, y: title != nil ? 35 : 0)

view.transform = .init(translationX: 0, y: title != nil ? 35 : 0)

alertView.view.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
alertView.view.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true

self.pickerCompletion = completion

// close button
let close = UIButton(frame: CGRect(x: buttonX - 10 , y: 10, width: image!.size.width, height: image!.size.height))
close.tintColor = .gray
close.setImage(image!, for: .normal)
close.addTarget(self, action: #selector(pickerClose(_:)), for: .touchUpInside)
close.translatesAutoresizingMaskIntoConstraints = false
alertView.view.addSubview(close)

let topAncor = alertView.view.topAnchor.constraint(equalTo: close.topAnchor)
topAncor.isActive = true
topAncor.constant = -10

let rightAncor = alertView.view.rightAnchor.constraint(equalTo: close.rightAnchor)
rightAncor.isActive = true
rightAncor.constant = 10

// ok button
let ok = UIAlertAction(title: "Ok", style: .default) { (action) in
completion?(false)
Expand Down

0 comments on commit 767935a

Please sign in to comment.