图形动画的完成块

时间:2016-10-04 07:57:48

标签: ios objective-c animation

我的问题是我一个接一个地进行2个图形动画,但它们是一起完成的。 我想用完成块写一个方法,但是我做错了什么,或者还有另一种方法可以做到这一点。

动画是移出屏幕的uiview(closeView)和viewcontroller关闭的默认动画。 我希望viewcontroller在视图动画结束时关闭。

这就是我所做的

    # Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php


# File modified on Sun Mar 30 01:22:23 2014 by server
# For security reasons, mod_php is not used on this server. Use a php.ini file for php directives
# php_value max_execution_time 90

# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine on



#RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
# Change 'subdirectory' to be the directory you will use for your main domain.

#RewriteCond %{REQUEST_URI} !^/site/


# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /site/$1

# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.


RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ site_en/index.html [L]


# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change domain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
# Change 'site to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/learning/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'site' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /learning/$1
# Change domain.com to be your main domain again.
# Change 'site' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ learning/index.html [L] 

使用:

- (void)closeViewWithCompletion:(void (^) (BOOL finish))handler {
    [self closeView];
    handler(YES);
}

-(void) closeView{
        [self.myview setFrame:CGRectMake(
                                          -self.myview.frame.size.width
                                          , self.myview.frame.origin.y
                                          , self.myview.frame.size.width
                                          , self.view.frame.size.height
                                          )];


        CATransition *animation = [CATransition animation];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromRight];
        [animation setDuration:.50];
        [animation setDelegate:self];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        CALayer *layer = [self.myview layer];
        [layer addAnimation:animation forKey:nil];

        [UIView animateWithDuration:0.5 animations:^{
            [greyMask setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0]];
        } completion:^(BOOL finished) {
            [greyMask removeFromSuperview];
        }];
}

1 个答案:

答案 0 :(得分:1)

handler动画完成后,

completionBlock内呼叫closeView阻止。

- (void)closeViewWithCompletion:(void(^)(BOOL finish))handler {

    //closeView Animation 
     [UIView animateWithDuration:duration delay:0 options: UIViewAnimationOptionCurveEaseOut animations:^{
        //code for close view animation
    } completion:^(BOOL finished) {
        handler(YES) //call your handler in completion block
    }];
 }

[vc closeViewWithCompletion:^(BOOL finish) {
     [self.navigationController popViewControllerAnimated:true];
 }];