将一个 UIImageView 与另一个 UIImageView 一起推送,可能吗?
是否可以平移 UIImageView,并且当它与另一个 UIImageView 的框架相交时,是否可以让另一个 UIImageView 被另一个 UIImageView 推动而不只是越过它?我希望这是有道理的!
如果可能的话,您能给我一些关于如何实施这个的想法吗?
我想它会像...
如果框架在 x/y 轴上从左或右与框架相交,则让另一个框架沿相同方向移动,距离与推动框架相同。虽然这个逻辑对我来说有点道理,但我不确定如何在代码中实现它。
我真的很感激你能提供的任何建议。
Is it possible to pan a UIImageView and when it intersects with the frame of another UIImageView, have that other UIImageView be pushed around by the other UIImageView without just passing over it? I hope that makes sense!
If it is possible, could you give me some ideas on how I'd go about implementing this?
I imagine it would go something like...
If frame intersects frame from left or right on the x/y axis, have the other frame move in that same direction with same distance as the pushing frame. While that logic somewhat makes sense to me, I'm not sure how I'd implement that in code.
I'd really appreciate any advice you can offer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以,你只关心左/右平移...
让我们假设你有 2 个 UIImageViews,一个 & 。 b,作为其他一些 UIView 的子视图并定义为某个类的类成员。
您可以通过创建 UIPanGestureRecognizer 实例并使用方法 addGestureRecognizer 将它们添加到每个 UIImageView 来获得检测每个视图上的平移手势(拖动触摸)的帮助:
创建每个 UIPanGestureRecognizer 时,您需要指定一个选择器来接收手势事件。假设它被称为 didMove:
现在,一些示例代码:
它可能不完全是您所需要的,但它应该让您很好地了解如何完成它。
So, you're only concerned with left / right panning...
Let's assume you have 2 UIImageViews, a & b, as subviews of some other UIView and defined as class members of some class.
You can get help detecting panning gestures (dragging touches) on each of these views by creating instances of UIPanGestureRecognizer and adding them to each UIImageView using method addGestureRecognizer:
When creating each UIPanGestureRecognizer, you need to designate a selector to receive the gesture events. Let say it's called didMove:
Now, some sample code:
It may not be exactly what you need, but it should give you a good idea how it could be done.
听起来你最好使用像 Cocos2D 这样的东西,它有精灵、交叉点和一些基本的物理原理......
Sounds like you'd better use something like Cocos2D with it's sprites, intersections and some basic physics...
你可以这样做,
首先,创建一个 UIImageView 并为其分配一个 UIImage。
其次,当用户滑动或做出任何手势时,只需通过再次设置卡片的框架来更改卡片的坐标。
由于您希望卡片滑走,因此必须将 x 坐标更改为负值,以便卡片从视图中滑落。
上面所说的重构 imageview 的代码应该在 UIView setAnimation 方法组中给出......并具有所需的延迟。
为了实现推送效果,请在同一动画代码块中调用一个方法,该方法创建一个新的图像视图(与第一个图像视图具有相同的名称)并将其保留在视图之外。那超出了屏幕的宽度。 (不要忘记释放之前被推开的卡片)
然后再次为此图像视图创建一个新框架,使其出现在屏幕中央......当以上三步代码放入动画块中时UIView或UIImageView的代码加上延迟时间,就可以达到需要的效果。
希望这会有所帮助......
快乐编码......
You can do it like this,
First, Create an UIImageView and assign an UIImage to it.
Second, When the user swipes or makes any gesture just change the coordinates of the card by setting its frame again.
Since u want the card to slide away, you have to change the x coordinate to a negative value such that it slides off from the view.
The above said code of reframing the imageview should be given within a UIView setAnimation group of methods...with a required delay.
To achieve the push effect have a method called within the the same animation block of codes which creates a new imageview (having same name as that of first imageview) and keep it out of the view. That is beyond the width of the screen. (dont forget to release the card which was pushes away previously)
Then subsequently again make a new frame for this imageview such that it appears in the centre of the screen....When above three steps of code are put within the animation block of code for UIView or UIImageView with a delay time , u will achieve the required effect.
Hope this helps....
happy coding....