我有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