forked from xamarin/ios-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewController.cs
86 lines (70 loc) · 1.89 KB
/
ViewController.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
using System;
using System.Drawing;
using OpenTK.Graphics.ES20;
using OpenTK;
using MonoTouch.OpenGLES;
using MonoTouch.CoreAnimation;
using MonoTouch.Foundation;
using MonoTouch.GLKit;
using MonoTouch.UIKit;
namespace OpenGLScroller
{
public class ViewController : GLKViewController
{
CADisplayLink displayLink;
UIScrollView scrollView;
public CubeView CubeView { get; set; }
public ViewController () : base ()
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
View = CubeView = new CubeView (View.Frame);
scrollView = new UIScrollView ();
scrollView.Frame = CubeView.ScrollableFrame;
scrollView.ContentSize = CubeView.ScrollableContentSize;
scrollView.ShowsHorizontalScrollIndicator = false;
scrollView.Scrolled += Scrolled;
scrollView.DraggingStarted += DraggingStarted;
scrollView.DraggingEnded += DraggingEnded;
scrollView.DecelerationEnded += DecelerationEnded;
scrollView.Hidden = true;
View.AddSubview (scrollView);
UIView dummyView = new UIView (scrollView.Frame);
dummyView.AddGestureRecognizer (scrollView.PanGestureRecognizer);
View.AddSubview (dummyView);
}
void Scrolled (object sender, EventArgs ea)
{
CubeView.scrollOffset = scrollView.ContentOffset;
}
void DraggingStarted (object sender, EventArgs ea)
{
StartDisplayLinkIfNeeded ();
}
void DraggingEnded (object sender, DraggingEventArgs ea)
{
if (!ea.Decelerate)
StopDisplayLink ();
}
void DecelerationEnded (object sender, EventArgs ea)
{
StopDisplayLink ();
}
void StartDisplayLinkIfNeeded ()
{
if (displayLink == null) {
displayLink = CADisplayLink.Create (() => CubeView.Display ());
displayLink.AddToRunLoop (NSRunLoop.Main, NSRunLoop.UITrackingRunLoopMode);
}
}
void StopDisplayLink ()
{
if (displayLink != null) {
displayLink.Invalidate ();
displayLink = null;
}
}
}
}