-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExtensions.cs
56 lines (46 loc) · 1.77 KB
/
Extensions.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
using System;
using System.Linq;
using UIKit;
namespace AutoScroll
{
public static class Extensions
{
public static UITapGestureRecognizer DismissKeyboardOnTap(this UIView view)
{
// Add gesture recognizer to hide keyboard
var tap = new UITapGestureRecognizer { CancelsTouchesInView = false };
tap.AddTarget(() => view.EndEditing(true));
tap.ShouldReceiveTouch = (recognizer, touch) => !(touch.View is UIControl);
view.AddGestureRecognizer(tap);
return tap;
}
public static UIView FindFirstResponder(this UIView view)
{
if (view.IsFirstResponder)
return view;
return view.Subviews
.Select(subView => subView.FindFirstResponder())
.FirstOrDefault(firstResponder => firstResponder != null);
}
public static UIView FindSuperviewOfType(this UIView view, UIView stopAt, Type type)
{
if (view.Superview == null)
return null;
if (type.IsInstanceOfType(view.Superview))
return view.Superview;
return !Equals(view.Superview, stopAt) ? view.Superview.FindSuperviewOfType(stopAt, type) : null;
}
public static UIView FindTopSuperviewOfType(this UIView view, UIView stopAt, Type type)
{
var superview = view.FindSuperviewOfType(stopAt, type);
var topSuperView = superview;
while (superview != null && !Equals(superview, stopAt))
{
superview = superview.FindSuperviewOfType(stopAt, type);
if (superview != null)
topSuperView = superview;
}
return topSuperView;
}
}
}