Reputation: 1012
I try to write application in Xamarin which uses page controll for switching images, I used this article as tutorial http://iosmadesimple.blogspot.ru/2013/01/page-control-for-switching-between-views.html but I can't scroll my images, and in debug it is not stoping at breakpoint in method scrolled. My code:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();;
scrollView.PagingEnabled = true;
scrollView.ContentSize = new SizeF(scrollView.Frame.Width * 2,scrollView.Frame.Height);
scrollView.ShowsHorizontalScrollIndicator = false;
scrollView.ShowsVerticalScrollIndicator = false;
scrollView.ScrollsToTop = false;
scrollView.Scrolled += delegate
{
var pageWidth = scrollView.Frame.Size.Width;
var page = (int)Math.Floor((scrollView.ContentOffset.X - pageWidth / 2) / pageWidth) + 1;
pageControl.CurrentPage = page;
};
var pic = new UIImage ("first.png");
var img = new UIImageView (pic);
var pic2 = new UIImage ("second.png");
var img2 = new UIImageView (pic2);
var imageArray = new UIImageView[]{img,img2};
for (var i = 0; i < 2; i++) {
RectangleF frame = new RectangleF ();
frame.X = scrollView.Frame.Size.Width * i;
frame.Y = 0;
frame.Size = scrollView.Frame.Size;
imageArray [i].Frame = frame;
scrollView.AddSubview (imageArray[i]);
}
scrollView.ContentSize = new SizeF(scrollView.Frame.Size.Width*2,scrollView.Frame.Size.Height);
}
also I tryed to create my own delegate class and set scrollView.Delegate = new ScrollViewDelegate(this).
can it be problem if I use storyboard? In connection inspector for scroll view: Outlets: delegate - Page control Referencing Outlets: scrollView FirstViewController for page control: Referencing Outlets: delegate = Scroll View
Upvotes: 0
Views: 3494
Reputation: 488
I have done this once. What you need to do is: You need 2 view controllers,
UIPageviewController*(parent controller)* ImageViewController (controller that has UIImageView)
Hope this helps
Upvotes: 1