Objective-C - 带块的动画按钮?

时间:2013-09-04 16:14:07

标签: ios objective-c animation objective-c-blocks

我有一个UIScrollView和一个UIButton。我正在使用块来设置它们的动画,但是当UIScrollView执行时按钮不会动画?你能不为这样的按钮设置动画吗?

任何帮助都将受到极大的赞赏!

- (void)viewDidLoad
{

    [super viewDidLoad];

    draw1 = 0;
    scrollView.frame = CGRectMake(0, -200, 768, 200);
    [scrollView setContentSize:CGSizeMake(768, 200)];

    openMenu.frame = CGRectMake(680, 100, 55, 55);

}



- (IBAction)openMenu:(id)sender {

    if (draw1 == 0) {

        draw1 = 1;
        CGRect optionsDrawer = scrollView.frame;
        CGRect optionsButton = openMenu.frame;
        optionsDrawer.origin.y += 200;

        [UIView animateWithDuration:0.5
                         animations:^{
                             scrollView.frame = optionsDrawer;
                             openMenu.frame = optionsButton;
                         }];
    } else {

        draw1 = 0;

        CGRect optionsDrawer = scrollView.frame;
        CGRect optionsButton = openMenu.frame;
        optionsDrawer.origin.y -= 200;
        [UIView animateWithDuration:0.5
                         animations:^{
                             scrollView.frame = optionsDrawer;
                             openMenu.frame = optionsButton;
                         }];

    }

}

1 个答案:

答案 0 :(得分:0)

啊!我忘了将原点添加到按钮中!糟糕!

修正了添加到每个:

optionsButton.origin.y += 200;