如何将对象移动到Objective C中的特定位置?

时间:2016-03-15 17:38:19

标签: objective-c

我目前正在开发各种卡牌游戏,当用户玩牌时,我希望该牌从玩家手中的当前位置移动到"面朝上&#34 ;堆在屏幕上。

编辑:要回答一些问题,并使问题/答案清晰,这是我的一些代码。

+(id)card:(NSString*)suit :(int) value {
HHCard *card = [HHCard new];
card.value = value;
card.suit = suit;
//used for selection of cards during human turn
card.isSelected = false;
return card;
}

3 个答案:

答案 0 :(得分:0)

您的卡必须与某种UIView相关联。为什么不使用:

[UIView animateWithDuration:animations:]

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/clm/UIView/animateWithDuration:animations

然后在您的动画块中,您只需将x和y坐标更改为您想要卡片的位置。它会为你制作动画。

答案 1 :(得分:0)

我很抱歉没有尽快回答这个问题,但答案很简单。为了移动一个对象,在这个例子中是一张卡片。到屏幕上的所需位置,创建一个CGPoint,其中包含您希望对象移动的点,然后让对象运行SKAction moveTo:(CGPoint)持续时间:(NSTimeInterval)。

https://www.nuget.org/packages/FluentValidation/

答案 2 :(得分:-1)

他们提供了4种方法,通过它们我们可以跟踪对视图的触摸。方法如下:

  • (void)touchesBegan:(NSSet *)触及withEvent:(UIEvent *)事件;
  • (void)touchesMoved:(NSSet *)触及withEvent:(UIEvent *)事件;
  • (void)touchesEnded:(NSSet *)触及withEvent:(UIEvent *)事件;
  • (void)touchesCancelled:(NSSet *)触及withEvent:(UIEvent *)事件

您只需在控制器类中应用这些方法,然后相应地跟踪视图在这些方法中的位置。

希望这可能会有所帮助。