0
我試圖在主視圖中縮放UIButton,當我首先按動按鈕時,按鈕放大,當我再按一次它縮小,但是當我再次按下它時放大..什麼也沒有發生。這裏是我的代碼:CGAffineTransformScale a UIButton
方法進行放大和縮小是在一個Objective-C的類別在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];
}];
}
感謝, 牛頓
夥計,真棒..我沒有看到..!我會在家裏測試它,並給你你的大拇指......;)謝謝。 –
是的..它能正常工作..非常感謝。 –