Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actionsheet presentation style option #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

spnkr
Copy link

@spnkr spnkr commented Nov 2, 2019

Use showAsActionSheet() instead of show() to present the alert as an action sheet (iPhone only). On iPads, the alert is always shown with the alert style. See below.


Why no actionSheet style on iPads?

On iPads, presenting a UIAlertController requires a sender (UIBarButtonItem), or an explicit frame. this is easy enough to do using AlertManager.sharedInstance.parentController. But then the alert doesn't support device rotation. easier to just ignore the request for the actionSheet style on devices that use popoverPresentationControllers.

to see what i mean, replace this

AlertManager.sharedInstance.parentController.present(alertController, animated: true, completion: nil)

with this

if let popoverController = alertController.popoverPresentationController {
  popoverController.sourceView = AlertManager.sharedInstance.parentController.view
  popoverController.sourceRect = CGRect(x: AlertManager.sharedInstance.parentController.view.bounds.midX, y: AlertManager.sharedInstance.parentController.view.bounds.midY, width: 0, height: 0)
  popoverController.permittedArrowDirections = []
}
AlertManager.sharedInstance.parentController.present(alertController, animated: true, completion: nil)

on an ipad and try rotation.

Also added destructive button to demo project

Signed-off-by: spnkr <wjessop@gmail.com>
Signed-off-by: spnkr <wjessop@gmail.com>
@spnkr
Copy link
Author

spnkr commented Nov 2, 2019

Oh yeah, the iOS target for the demo project is ios 13.1. but the base library is unchanged, at 10.0.

Signed-off-by: spnkr <wjessop@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant