Reputation: 3655
I'm using Monotouch to develop an iPhone application. I'm aware there are answers out there for this question already for Objective-C. For example:
Stop UIWebView from bouncing vertically
This answer is ideal. I figured I could just take it, and turn it into C# and it'll be fine.
The Objective-C code is:
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
I couldn't find anything similar to isSubclassOfClass:
in C# and after a little experimenting, I found my webView only contained one subview, which was a scrollview. So I tried the following C# code:
foreach (var view in webView.Subviews)
{
webView.Subviews[0].Bounces = false;
}
This should've worked except the returned type of webView.Subviews[0]
was type UIView
not UIScrollView
- this meant the compiler complains the UIView
doesn't have a property "bounces" (which is correct.)
So my question is, what would be the appropriate way of doing this? Is there a way I can get the UIScrollView instance from the subviews? Or am I going about this completely the wrong way?
Thanks.
Upvotes: 0
Views: 1099
Reputation: 2208
Luke,
If you're wanting to follow the same example as the Obj-C then you will want to do something like this;
foreach (var view in webView.Subviews.OfType<UIScrollView>())
{
view.Bounces = false;
}
since the example above assumes that the first view in a webView is a UIScrollView, which may change in the future.
Hope this helps,
ChrisNTR
Upvotes: 4
Reputation: 3504
This is a stab in the dark but:
((UIScrollView)webView.Subviews[0]).Bounces = false;
Upvotes: 2