18

iOSでサブビューを追加する際にバウンスまたはポップアップスタイルのアニメーションを与える方法は? UIAlertView外観スタイルに似たものが必要です。同じことを行う方法がいくつかあることは知っていますが、ここでは基本的な[UIView animateWithDuration: ...];ブロックを使用することを好みtransformます。ポップアップ効果を得るためにここで使用する必要がある方法について、助けてもらえますか?

ありがとう

4

6 に答える 6

51

Animationポップアップ スタイルの場合:

迅速

    yourView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
    UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {() -> Void in
        yourView.transform = .identity
    }, completion: {(finished: Bool) -> Void in
        // do something once the animation finishes, put it here
    })

Reverse Animationhiding_same View

    yourView.transform = .identity
    UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {() -> Void in
        yourView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
    }, completion: {(finished: Bool) -> Void in
        // do something once the animation finishes, put it here
        yourView.isHidden = true
    })

Objective-C

yourView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    yourView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
    // do something once the animation finishes, put it here
}];

Reverse Animationhiding_same View

 yourView.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    yourView.transform = CGAffineTransformMakeScale(0.01, 0.01);
} completion:^(BOOL finished){
    yourView.hidden = YES;
}];
于 2012-11-06T11:51:33.923 に答える
2

私はすでに前に行っていました... このコードから私のアイデアを得ることができます。これはあなたを助けるかもしれません。問題がある場合は、お知らせください。

- (CGAffineTransform)transformForOrientation {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationLandscapeLeft) {
    return CGAffineTransformMakeRotation(M_PI*1.5);
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
    return CGAffineTransformMakeRotation(M_PI/2);
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
    return CGAffineTransformMakeRotation(-M_PI);
} else {
    return CGAffineTransformIdentity;
}
}



-(void)showCustomAlertView{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
//self (this view pop up like alert)
[window addSubview:self];
self.transform = CGAffineTransformScale([self transformForOrientation], 0.001, 0.001);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/1.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)];
self.transform = CGAffineTransformScale([self transformForOrientation], 1.1, 1.1);
[UIView commitAnimations];
}

- (void)bounce1AnimationStopped {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)];
self.transform = CGAffineTransformScale([self transformForOrientation], 0.9, 0.9);
[UIView commitAnimations];
}


- (void)bounce2AnimationStopped {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kTransitionDuration/2];
self.transform = [self transformForOrientation];
[UIView commitAnimations];
}
于 2013-01-17T06:14:17.970 に答える
1

これらの3つの方法を試してください。

****vwTempは私のカスタムアラートビューです****

- (void)showAlertView
{
    vwTemp.transform = CGAffineTransformMakeScale( 0.001, 0.001);
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/1.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)];
    vwTemp.transform = CGAffineTransformMakeScale( 1.1, 1.1);

   [UIView commitAnimations];   
}

 - (void)bounce1AnimationStopped 
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)];
    vwTemp.transform = CGAffineTransformMakeScale (0.9, 0.9);
    [UIView commitAnimations];
}



- (void)bounce2AnimationStopped
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration/2];
    [UIView setAnimationDelegate:self];

    vwTemp.transform =  CGAffineTransformIdentity;
    [UIView commitAnimations];
}
于 2012-11-06T11:56:16.350 に答える
0
    yourView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3/1.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)];
    [self.view addSubview:yourView];
    yourView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
    [UIView commitAnimations];

アニメーションを 2 回バウンスした後、次の 2 つの方法が使用されます。

- (void)bounce1AnimationStopped {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3/2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)];
    yourView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
    [UIView commitAnimations];
}

- (void)bounce2AnimationStopped {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3/2];
    yourView.transform = CGAffineTransformIdentity;
    [UIView commitAnimations];
}
于 2012-11-06T11:52:30.963 に答える