-
Notifications
You must be signed in to change notification settings - Fork 912
/
FirstViewController.swift
65 lines (50 loc) · 2.01 KB
/
FirstViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import UIKit
class FirstViewController : UIViewController {
let which = 3
@IBAction func doPresent(_ sender: Any?) {
switch which {
case 1:
let vc = ExtraViewController()
// vc.modalPresentationStyle = .overFullScreen
// vc.modalTransitionStyle = .flipHorizontal
self.present(vc, animated: true)
case 2:
// in iOS 8+, this works on iPhone as well as iPad!
// presented vc appears over first vc *inside* tabbed interface
let vc = ExtraViewController()
self.definesPresentationContext = true
vc.modalPresentationStyle = .currentContext
self.present(vc, animated: true)
case 3:
let vc = ExtraViewController()
// vc.modalTransitionStyle = .flipHorizontal
self.definesPresentationContext = true
// comment out next line to see the difference
self.providesPresentationContextTransitionStyle = true
self.modalTransitionStyle = .flipHorizontal
vc.modalPresentationStyle = .currentContext
vc.modalPresentationCapturesStatusBarAppearance = true
self.present(vc, animated: true)
default: break
}
}
override func viewDidLoad() {
self.tabBarController?.delegate = self
}
}
/*
cases 2 and 3 also demonstrate a nasty bug
to see it:
start in First view, tap button to present
switch to Second view
switch back to First view, tap button to dismiss
black view, that's the bug
still there in iOS 9! (still there in iOS 11) (still there in iOS 13)
The following code stops the user from doing that, and so avoids the bug
*/
extension FirstViewController : UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
return self.presentedViewController == nil
return true
}
}