在應用中的CAKeyframeAnimation,代碼如下:
-(IBAction)start:(id)sender {
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(600, 150)];
[path addLineToPoint:CGPointMake(600, 300)];
[path addLineToPoint:CGPointMake(450, 300)];
[path addLineToPoint:CGPointMake(450, 150)];
[path addLineToPoint:CGPointMake(600, 150)];
CAKeyframeAnimation *move = [CAKeyframeAnimation animationWithKeyPath:@"position"];
move.path = path.CGPath;
move.duration = 6.0f;
move.repeatCount = 100;
[testButton.layer addAnimation:move forKey:@"move"];
怎麼讓動畫進行的時候按鈕也能用?試了好幾種方法也沒實現。
謝謝指教
你要按鈕在動畫期間可以按,就需要自己的動畫
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *t = [touches anyObject];
CGPoint location = [t locationInView:self.view];
for (UIButton *button in self.buttonsOutletCollection)
{
if ([button.layer.presentationLayer hitTest:location])
{
// This button was hit whilst moving - do something with it here
break;
}
}
}