我有UILabels获得在屏幕上左右移动的动画,并且我希望能够在动画时拖动它们。任何人有任何想法如何做到这一点?iOS - UILabels和手势
WordLabel *firstWordLabel = [[WordLabel alloc] initWithFrame:CGRectMake(x, 100, 10, 35) andWithWord:firstWord];
firstWordLabel.text = firstWord.word;
[firstWordLabel sizeToFit];
firstWordLabel.userInteractionEnabled = YES;
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(labelDragged:)];
[firstWordLabel addGestureRecognizer:gesture];
[self.view addSubview:firstWordLabel];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGRect newRect = firstWordLabel.frame;
newRect.origin.x = floor(screenWidth/2);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
firstWordLabel.frame = newRect;
[UIView commitAnimations];
你应该从Facebook看看POP(https://github.com/facebook/pop)。据我所知,这是造成这个框架的主要原因。 – dasdom
它是否允许您向其添加手势? – Mikerizzo
我不知道。但它是开源的。所以你可以看看你自己。 – dasdom