0

我有几个按钮位于视图(故事板)的不同位置,我希望当我单击它们中的每一个以转到给定点时,

为此,我通过以下方式保持它们的位置和初始大小:

CGPoint originalCenter1;
CGRect originalsize1;

CGPoint originalCenter2;
CGRect originalsize2;

在 viewDidLoad

originalCenter1 = self.boton1.center;
originalsize1 = self.boton1.frame;

originalCenter2 = self.boton2.center;
originalsize2 = self.boton2.frame;

以及与每个按钮关联的 IBAction、动画...

-(IBAction)move:(id)sender{

UIButton * pressedbutton = (UIButton*)sender;

[UIView animateWithDuration:3.0 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{

    CGAffineTransform scale = CGAffineTransformMakeScale(3.0, 3.0);
    pressedbutton.transform = scale;
    switch(pressedbutton.tag)
    {
        case 0:     
            pressedbutton.center = CGPointMake(784, 340);

            break;
        case 1:
            pressedbutton.center = CGPointMake(784, 340);

            break;

当所有人都已移动时,我有一个刷新按钮,可将我置于初始位置。

-(IBAction)refresh:(id)sender{

self.boton1.frame = originalsize1;
self.boton1.center = originalCenter1;
self.boton1.alpha=1;

self.boton2.frame = originalsize2;
self.boton2.center = originalCenter2;
self.boton2.alpha=1;

问题是下一次脉冲按钮时,移动到动画中显示的位置,但“缩放”效果不起作用!

有什么帮助吗??

谢谢。

4

1 回答 1

0

我认为你应该使用块试试这个......

- (IBAction)tap:(UITapGestureRecognizer *)gesture
{
    CGPoint tapLocation = [gesture locationInView:self.view1];
    for (UIView *view in self.view1.subviews) {
        if (CGRectContainsPoint(view.frame, tapLocation)) {
            [UIView animateWithDuration:5.0 animations:^{
                [self setRandomLocationForView:view];
            }];
        }
    }
}


- (void)setRandomLocationForView:(UIView *)view
{
    [view sizeToFit];
    CGRect sinkBounds = CGRectInset(self.view1.bounds, view.frame.size.width/2, view.frame.size.height/2);
    CGFloat x = your location.x;
    CGFloat y = yout location.y;
    view.center = CGPointMake(x, y);
}
于 2013-10-23T12:16:10.633 回答