【发布时间】:2011-02-22 09:05:55
【问题描述】:
我遇到了一个简单动画的问题。我有一个 UIImageView 和一个不可见的按钮。当按下此按钮时,图像会全屏显示,当用户按下全屏时,图像会返回。这很好用。问题是,当图像重新调整大小时,界面会被阻止(它不会崩溃),它只会阻止所有用户交互。虽然我有与视图层次结构相关的理论,但我看不出问题出在哪里......
这是相关动画的完整代码。
- (IBAction) imageButtonPressed {
NSLog(@"Entered imageButtonPressed method");
imageFullscreenView = [[UIImageView alloc]
initWithFrame:CGRectMake(8, 72, 72, 72)];
[imageFullscreenView setImage:[self.coolView image]];
[imageFullscreenView setContentMode:UIViewContentModeScaleAspectFit];
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
[mainWindow addSubview:imageFullscreenView];
// With Concurrent Block Programming:
[UIView animateWithDuration:0.5 animations:^{
[imageFullscreenView setFrame:CGRectMake(0, 0, 320, 480)];
imageFullscreenView.transform = CGAffineTransformMakeScale(1, 1);
imageButton = [[[UIButton alloc]
initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[[[UIApplication sharedApplication] keyWindow] addSubview:imageButton];
[[[UIApplication sharedApplication] keyWindow]
addSubview:imageFullscreenView];
} completion: ^(BOOL finished) {
NSLog(@"entered First animation");
[self animationDidStop:@"Expand" finished:YES context:nil];
}];
}
- (void) animationDidStop:(NSString *) animationID finished:(BOOL)
finished context:(void *)context {
NSLog(@"Entered animationDidStop");
NSLog(@"animationID: %@", animationID);
if ([animationID isEqualToString:@"Expand"]) {
NSLog(@"Entered First if");
NSLog(@"imageButton enabled: %d", self.imageButton.enabled);
NSLog(@"coolButton enabled: %d", coolButton.enabled);
NSLog(@"uncoolButton enabled: %d", uncoolButton.enabled);
NSLog(@"reportButton enabled: %d", self.reportButton.enabled);
imageButton.enabled = YES;
imageButton = [[[UIButton alloc]
initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[imageButton addTarget:self
action:@selector(didViewFullscreen:)
forControlEvents:UIControlEventTouchDown];
[[[UIApplication sharedApplication] keyWindow] addSubview:imageButton];
imageButtonPressed = NO;
} else {
}
}
- (void) didViewFullscreen: (id) selector {
NSLog(@"Entered didViewFullscreen");
[imageButton removeFromSuperview];
[UIView animateWithDuration:0.5 animations:^{
[imageFullscreenView setFrame:CGRectMake(8, 72, 72, 72)];
} completion: ^(BOOL finished){
NSLog(@"FINISHED");
//NSLog(@"imageButton enabled: %d", self.imageButton.enabled);
NSLog(@"coolButton enabled: %d", coolButton.enabled);
NSLog(@"uncoolButton enabled: %d", uncoolButton.enabled);
NSLog(@"reportButton enabled: %d", self.reportButton.enabled);
//[imageFullscreenView setFrame:CGRectMake(20, 72, 280, 192)];
imageFullscreenView.transform = CGAffineTransformMakeScale(1, 1);
[imageFullscreenView removeFromSuperview];
imageButton = [[[UIButton alloc]
initWithFrame:CGRectMake(20, 72, 280, 192)] autorelease];
[imageButton addTarget:self
action:@selector(imageButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
[imageButton setImage:nil forState:UIControlStateNormal];
[[[UIApplication sharedApplication] keyWindow] addSubview:self.imageButton];
}];
}
【问题讨论】:
标签: iphone objective-c animation block