滑动图片与Xamarin [英] Sliding Images with Xamarin
问题描述
我很新的Xamarin。我所试图做的是建立一个简单的应用程序,它有3个图像。每个图像需要水平滑动来显示一个图像。我从孩子们的游戏叫混搭这一理念。游戏中可以让你改变一个卡通动物的头部,身体和脚。
I am very new to Xamarin. What I am trying to do is build a simple application that has 3 images on it. Each image needs to slide horizontally to show the next image. I got this idea from a children's game called "mix and match". The game lets you change the head, body and feet of a cartoon animals.
所以,如果我有一组被分成三分之二(头部,身体,脚)5张图片,我怎么能在屏幕上显示图像,所以我可以让他们滑落?
So if I have a set of 5 images that are split into thirds (head,body,feet), how can I display the images on the screen so I can get them to slide?
我试图叠加3画廊控件,但我无法得到的图像,以填补屏幕。
I tried to stack 3 gallery controls but I could not get the images to fill the screen.
的屏幕应该是这个样子;
The screen should look something like this;
这能建在Xamarin的Android或IOS?
Can this be built in Xamarin for Android or IOS?
感谢您的帮助。
推荐答案
对于iOS,你可以使用 UIPageControl
。你有头,身,脚不同的 UIPageControl
对象。这个想法是,你将有一个的UIView
与的UIScrollView
(另3台)。 的UIScrollView
将包含身体的各个不同部分(例如头)。 的PageControl
将处理轻扫手势识别和动画,你将设置其中一部分的UIScrollView
应<$显示C $ C> UIPageControl 的活动中的ValueChanged
。在code会是这个样子:
For iOS you could use UIPageControl
. You would have a different UIPageControl
object for Head, Body, Feet. The idea is that you will have an UIView
with a UIScrollView
(also three of them). UIScrollView
will contain all the different parts of body (e.g. heads). PageControl
will handle the swipe gesture recognition and animations and you will set which part of the UIScrollView
should be shown in UIPageControl
s event ValueChanged
. The code will look something like this:
在 viewDidLoad中
:
首先,添加的五个头部分的UIScrollView
。我假设你有一个数组的UIView
这叫这五头部分 headPageViews
。
In ViewDidLoad
:
First you add the five head parts to UIScrollView
. I assume that you have these five head parts in an array of UIView
s called headPageViews
.
RectangleF frame;
for (int i=0; i<5; i++)
{
UIView pageView = headPageViews[i];
frame = headPageViews[i].Frame;
// change Frame.X so that the views are next to each other in scrollView
frame.X = i * this.scrollViewHead.Frame.Width;
pageView.Frame = frame;
this.scrollViewHead.AddSubViews(pageView);
}
在 viewDidLoad中
:接下来,您设置了 UIPageControl
您通过Interface Builder的补充:
In ViewDidLoad
: Next you set up the UIPageControl
which you added through interface builder:
this.pageControlHead = new UIPageControl(frame);
this.pageControlHead.HidesForSinglePage = true;
this.pageControlHead.ValueChanged += HandlePageControlHeadValueChanged;
this.pageControlHead.Pages = 5; this.viewHead.AddSubview(this.pageControlHead);
在某处code:最后,你处理的ValueChanged
事件:
private void HandlePageControlHeadValueChanged(object sender, EventArgs e)
{
this.scrollViewHead.SetContentOffset(new PointF(this.pageControlHead.CurrentPage * this.scrollViewHead.Frame.Width, 0), true);
}
重复这些步骤对其他身体部位,你应该有预期的效果。
Repeat these steps for other body parts and you should have the desired effect.
这篇关于滑动图片与Xamarin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!