Iphone 使用UIPAngestureRecognitor和CATTransferorM3DScale放大拖动的元素

Iphone 使用UIPAngestureRecognitor和CATTransferorM3DScale放大拖动的元素,iphone,cocoa-touch,ipad,core-animation,Iphone,Cocoa Touch,Ipad,Core Animation,我想在使用附加的UIPangestureRecognitor拖动的UIView上实现延迟的“放大”动画。 我一直在使用类似于以下代码的代码: UIView* innerView; CGPoint startingPoint; - (void)viewDidLoad { innerView = [[[UIView alloc] autorelease] initWithFrame:CGRectMake(0, 0, 200, 200)]; [[self view] add

我想在使用附加的UIPangestureRecognitor拖动的UIView上实现延迟的“放大”动画。 我一直在使用类似于以下代码的代码:

UIView* innerView;
CGPoint startingPoint;

- (void)viewDidLoad { 
        innerView = [[[UIView alloc] autorelease] initWithFrame:CGRectMake(0, 0, 200, 200)];
    [[self view] addSubview:innerView];

    [innerView setBackgroundColor:[UIColor blueColor]];

    [innerView addGestureRecognizer:[[[UIPanGestureRecognizer alloc] autorelease] initWithTarget:self action:@selector(pan:)]];

    // resize it later
    [self performSelector:@selector(anim) withObject:nil afterDelay:1.5];
}

 -(void)pan:(UIPanGestureRecognizer*)gr {
    CGPoint gesturePoint = [gr translationInView:[self view]];

    if (gr.state == UIGestureRecognizerStateBegan)
            startingPoint = innerView.center;
    else
        innerView.center = CGPointMake(startingPoint.x + gesturePoint.x,         startingPoint.y +gesturePoint.y);
}

-(void)anim{
    innerView.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1);
}
但在应用比例后拖动视图时,视图会“跳跃”。这种行为并不总是发生,而是以伪随机的方式发生的。
任何人都可以阐明这个问题或提出不同的方法?

尝试在视图而不是图层上进行变换,以便-anim方法如下所示:

-(void)anim
{
    [UIView beginAnimations:nil context:NULL];
    [innerView setTransform:CGAffineTransformMakeScale(1.5f, 1.5f)];
    [UIView commitAnimations];
}
问题是视图的根层默认情况下禁用了动画,因此它只会捕捉到您正在设置的变换

或者,如果需要为层设置动画,可以使用CABasicAnimation使用显式动画