This repository was archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathDetailViewController.cs
194 lines (158 loc) · 6.2 KB
/
DetailViewController.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using System.Collections.Generic;
using CoreGraphics;
using System.Linq;
using Foundation;
using UIKit;
namespace Popovers {
public partial class DetailViewController : UIViewController {
[Outlet]
public UIToolbar Toolbar { get; set; }
[Outlet]
public NSObject DetailItem { get; set; }
[Outlet]
public UIPopoverController DetailViewPopover { get; set; }
[Outlet]
public UIPopoverController BarButtonItemPopover { get; set; }
[Outlet]
public UIBarButtonItem MyBarButtonItem { get; set; }
[Outlet]
public UIButton Button1 { get; set; }
[Outlet]
public UIButton Button2 { get; set; }
[Outlet]
public UIButton Button3 { get; set; }
[Outlet]
public UIButton Button4 { get; set; }
[Outlet]
public UIButton Button5 { get; set; }
[Outlet]
public NSObject LastTappedButton { get; set; }
public UIPopoverController MainPopoverController { get; set; }
class SplitViewDelegate : UISplitViewControllerDelegate {
internal DetailViewController Parent { get; set; }
public override void WillHideViewController (UISplitViewController svc, UIViewController aViewController, UIBarButtonItem barButtonItem, UIPopoverController pc)
{
barButtonItem.Title = "MasterList";
var items = new List<UIBarButtonItem> (Parent.Toolbar.Items);
items.Insert (0, barButtonItem);
Parent.Toolbar.SetItems (items.ToArray (), true);
Parent.MainPopoverController = pc;
}
public override void WillShowViewController (UISplitViewController svc, UIViewController aViewController, UIBarButtonItem button)
{
var items = new List<UIBarButtonItem> (Parent.Toolbar.Items);
items.RemoveAt (0);
Parent.Toolbar.SetItems (items.ToArray (), true);
Parent.MainPopoverController = null;
}
public override void WillPresentViewController (UISplitViewController svc, UIPopoverController pc, UIViewController aViewController)
{
if (Parent.BarButtonItemPopover.PopoverVisible)
Parent.BarButtonItemPopover.Dismiss (true);
}
}
public DetailViewController (IntPtr handle) : base (handle)
{
// lost connection to DetailView.xib, create buttons manually for now
Button1 = new UIButton ();
Button2 = new UIButton ();
Button3 = new UIButton ();
Button4 = new UIButton ();
Button5 = new UIButton ();
}
//loads the DetailViewController.xib file and connects it to this object
public DetailViewController () : base ("DetailViewController", null)
{
// lost connection to DetailView.xib, create buttons manually for now
Button1 = new UIButton ();
Button2 = new UIButton ();
Button3 = new UIButton ();
Button4 = new UIButton ();
Button5 = new UIButton ();
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
var content = new PopoverContentViewController ();
DetailViewPopover = new UIPopoverController (content);
DetailViewPopover.PopoverContentSize = new CGSize (320, 320);
DetailViewPopover.DidDismiss += delegate { LastTappedButton = null; };
BarButtonItemPopover = new UIPopoverController (content);
BarButtonItemPopover.PopoverContentSize = new CGSize (320, 320);
BarButtonItemPopover.DidDismiss += delegate { LastTappedButton = null; };
}
[Action ("showPopover:")]
public void ShowPopover (NSObject sender)
{
// Set the sender to a UIButton.
UIButton tappedButton = (UIButton) sender;
// Present the popover from the button that was tapped in the detail view.
DetailViewPopover.PresentFromRect (tappedButton.Frame, View, UIPopoverArrowDirection.Any, true);
// Set the last button tapped to the current button that was tapped.
LastTappedButton = sender;
}
[Action ("showPopoverFromBarButtonItem:")]
public void ShowPopoverFromBarButtonItem (NSObject sender)
{
// Set the sender to a UIBarButtonItem.
UIBarButtonItem tappedButton = (UIBarButtonItem) sender;
// If the master list popover is showing, dismiss it before presenting the popover from the bar button item.
if (MainPopoverController != null)
MainPopoverController.Dismiss (true);
// If the popover is already showing from the bar button item, dismiss it. Otherwise, present it.
if (!BarButtonItemPopover.PopoverVisible)
BarButtonItemPopover.PresentFromBarButtonItem (tappedButton, UIPopoverArrowDirection.Any, true);
else
BarButtonItemPopover.Dismiss (true);
}
public override void WillRotate (UIInterfaceOrientation toInterfaceOrientation, double duration)
{
// If the detail popover is presented, dismiss it.
if (DetailViewPopover != null)
DetailViewPopover.Dismiss (true);
}
public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation)
{
if (LastTappedButton != null)
ShowPopover (LastTappedButton);
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
if (toInterfaceOrientation == UIInterfaceOrientation.Portrait || toInterfaceOrientation == UIInterfaceOrientation.PortraitUpsideDown) {
Button1.Frame = new CGRect (20, 64, 160, 160);
Button2.Frame = new CGRect (588, 64, 160, 160);
Button3.Frame = new CGRect (304, 422, 160, 160);
Button4.Frame = new CGRect (20, 824, 160, 160);
Button5.Frame = new CGRect (588, 824, 160, 160);
} else {
Button1.Frame = new CGRect (20, 64, 160, 160);
Button2.Frame = new CGRect (524, 64, 160, 160);
Button3.Frame = new CGRect (272, 311, 160, 160);
Button4.Frame = new CGRect (20, 568, 160, 160);
Button5.Frame = new CGRect (524, 568, 160, 160);
}
return true;
}
public void WillHideViewController (object sender, UISplitViewHideEventArgs args)
{
args.BarButtonItem.Title = "MasterList";
var items = new List<UIBarButtonItem> (Toolbar.Items);
items.Insert (0, args.BarButtonItem);
Toolbar.SetItems (items.ToArray (), true);
MainPopoverController = args.Pc;
}
public void WillShowViewController (object sender, UISplitViewShowEventArgs args)
{
var items = new List<UIBarButtonItem> (Toolbar.Items);
items.RemoveAt (0);
Toolbar.SetItems (items.ToArray (), true);
MainPopoverController = null;
}
public void WillPresentViewController (object sender, UISplitViewPresentEventArgs args)
{
if (BarButtonItemPopover.PopoverVisible)
BarButtonItemPopover.Dismiss (true);
}
}
}