2012-05-04 12 views
0

メインビューでUIButtonを拡大縮小しようとしていますが、最初にアクションボタンを押すとズームインし、もう一度押すとズームインしますが、もう一度押すと...何もここ..起こらないでズームが私のコードです:CGAffineTransformScale a UIButton

ZOOM INとZOOM OUT TO METHODSはUIViewの

- (void)viewDidLoad 
[super viewDidLoad]; 

//this button is being added in the storyboard 
[self.viewToZoom removeFromSuperview]; 

} 

- (IBAction)zoomButton:(id)sender { 

if (isShown) { 
    [self.view removeSubviewWithZoomOutAnimation:self.viewToZoom duration:1.0 option:0]; 
    isShown = NO; 
} else { 
    [self.view addSubviewWithZoomInAnimation:self.viewToZoom duration:1.0 option:0]; 
    isShown = YES; 
} 

} 

UIView+Animation.m 


- (void) addSubviewWithZoomInAnimation:(UIView*)view duration:(float)secs option:(UIViewAnimationOptions)option { 

CGAffineTransform trans = CGAffineTransformScale(view.transform, 0.01, 0.01); 

view.transform = trans; // do it instantly, no animation 
[self addSubview:view]; 
// now return the view to normal dimension, animating this tranformation 
[UIView animateWithDuration:secs delay:0.0 options:option 
       animations:^{ 
        view.transform = CGAffineTransformScale(view.transform, 100.0, 100.0); 
       } 
       completion:^(BOOL finished) { 
        NSLog(@"done"); 
       } ]; 
} 


- (void) removeSubviewWithZoomOutAnimation:(UIView*)view duration:(float)secs option:(UIViewAnimationOptions)option { 

// now return the view to normal dimension, animating this tranformation 
[UIView animateWithDuration:secs delay:0.0 options:option 
       animations:^{ 
        view.transform = CGAffineTransformScale(view.transform, 0.01, 0.01); 

       } 
       completion:^(BOOL finished) { 
        [view removeFromSuperview]; 
       }];  
} 

ON Objective-Cのカテゴリーに入るおかげで、 ニュートン

答えて

4

ニュートン、removeSubviewWithZoomOutAnimationがで終了すると10はビューの元のサイズを0.01に縮小したアフィン変換です。問題は、addSubviewWithZoomInAnimationをもう一度呼び出すと、もう一度0.01でスケールダウンしますが、今度はview.transformが0.0001にスケールダウンされることになります。これはあなたが探しているものではありません。

単にこのような両方のアニメーションの先頭にview.transform = CGAffineTransformIdentity;を追加します。

- (void) addSubviewWithZoomInAnimation:(UIView*)view duration:(float)secs option:(UIViewAnimationOptions)option { 
    view.transform = CGAffineTransformIdentity; 
    CGAffineTransform trans = CGAffineTransformScale(view.transform, 0.01, 0.01); 

    view.transform = trans; // do it instantly, no animation 
    [self addSubview:view]; 
    // now return the view to normal dimension, animating this tranformation 
    [UIView animateWithDuration:secs delay:0.0 options:option 
        animations:^{ 
         view.transform = CGAffineTransformScale(view.transform, 100.0, 100.0); 
        } 
        completion:^(BOOL finished) { 
         NSLog(@"done"); 
        } ]; 
} 


- (void) removeSubviewWithZoomOutAnimation:(UIView*)view duration:(float)secs option:(UIViewAnimationOptions)option { 
    view.transform = CGAffineTransformIdentity; 
    // now return the view to normal dimension, animating this tranformation 
    [UIView animateWithDuration:secs delay:0.0 options:option 
        animations:^{ 

         view.transform = CGAffineTransformScale(view.transform, 0.01, 0.01); 

        } 
        completion:^(BOOL finished) { 

         [view removeFromSuperview]; 
        }];  
} 

私はまた、あなたが迅速でかつズームアウト時にアニメーション結果を改善UIViewAnimationOptionBeginFromCurrentState UIViewAnimationOptionsを渡すことをお勧めします。

希望すると便利です。

+0

すごい、すごい..私はそれを見ていない.. !!私は自宅でそれをテストし、あなたの親指をあなたに与えるだろう..;)ありがとう。 –

+0

はい..それは良い男です..多くのありがとうございます。 –