打开新的ViewController

打开新的ViewController

我是iOS开发的新手,这是我关于SO的第一个问题。

我想创建“动画”。

当我点击UIButton时,我想慢慢地(大约0.5秒)将其向下移动10px,当我举起手指时,我想打开新的viewController。

我做了些什么,但我不知道该如何制作“动画”。

    UIImage *normalImage = [UIImage imageNamed:@"FirstImage"];
    UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    firstButton.frame = CGRectMake(31, 194, normalImage.size.width, normalImage.size.height);
    [firstButton setImage:normalImage forState:UIControlStateNormal];
    [firstButton addTarget:self action:@selector(showSecondViewController) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:firstButton];


- (void)showSecondViewController; {
    SecondViewController *secondViewController = [[SecondViewController alloc] init];
    secondViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:secondViewController animated:YES];
    [progressViewController release];
}

最佳答案

[UIView animateWithDuration:(NSTimeInterval)duration animations:^(void) {
    //put your animation result here
    //then it will do animation for you
} completion:^(BOOL finished){
    //do what you need to do after animation complete
}];

例如:
UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

//add firstButton to some view~
//....

firstButton.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.5 animations:^(void) {
    firstButton.transform = CGAffineTransformMakeTranslation(0,10);
} completion:^(BOOL finished){
    show your view controller~
}];

关于iphone - 向下移动UIButton 10px并打开新的ViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8588002/

10-08 23:10