Tuesday, 18 June 2013

How to add popUp/popOut like effects to UIVIew in cocos2d

You may have noticed the popUp and popOut effects of UIAlertView. We can even add such effects to our custom UIViews also. In this tutorial, we will teach you how to add popUp/popOut like effects to UIVIew in your cocos2d application.



in .h:

         UIView *profileView;


in .m:


    //First Create the UIView, and assign its alpha value to zero in the init method
        profileView = [[UIView alloc] init];
        profileView.frame = CGRectMake(50, 50, 270, 430);
        profileView.backgroundColor = [UIColor blueColor];
        profileView.alpha = 0;
        [[[CCDirector sharedDirector] openGLView] addSubview:profileView];

    // Call this function for Fade-In/PopUp
    -(void)effectFunction_FadeIn{
        profileView.transform = CGAffineTransformMakeScale(1.3, 1.3);
        profileView.alpha = 0;
        [UIView animateWithDuration:.35 animations:^{
            profileView.alpha = 1;
            profileView.transform = CGAffineTransformMakeScale(1, 1);
        }];
    }

    // Call this function for Fade-Out/PopOut
    -(void)effectFunction_FadeOut{
        profileView.transform = CGAffineTransformMakeScale(1.3, 1.3);
        profileView.alpha = 1;
        [UIView animateWithDuration:.35 animations:^{
            profileView.alpha = 0;
            profileView.transform = CGAffineTransformMakeScale(1, 1);
        }];
    }

No comments:

Post a Comment