开发者

modalviewcontroller animation too fast?

开发者 https://www.devze.com 2022-12-13 13:17 出处:网络
I\'m displaying a modal uiviewcontroller in the normal fashion: [self.navigationController presentModalViewC开发者_StackOverflow中文版ontroller:self.lvc animated:YES];

I'm displaying a modal uiviewcontroller in the normal fashion:

[self.navigationController presentModalViewC开发者_StackOverflow中文版ontroller:self.lvc animated:YES];
//do stuff

and later on...

[self.navigationController dismissModalViewControllerAnimated:FALSE];

The problem is that //do stuff is too fast, and the dismiss call happens before the presentation call animation completes, which has the net effect of not dismissing the view at all. if i set the animation parameter to false, everything works, every time, or if //do stuff takes longer than the animation...

what to do? sleep? (ick), cancel the transition animation somehow?

not enough info? here's some more:

the point is, sometimes the worker thread finishes before the original modalviewcontroller animation completes, which causes problems when dismissmodalviewcontroller is called. In summary, if you call dismiss before the present animation completes, you cannot actually dismiss it. I'm filing a bug w/ apple atm.

And here's the proof testcase:


#import "ModalbugsViewController.h"

@implementation modalbugsViewController
@synthesize modal;
-(void)dismisser {
    [self dismissModalViewControllerAnimated:TRUE];
}
-(void) sleeper:(NSNumber *) t{
    [NSThread sleepForTimeInterval:[t floatValue]];
    [self performSelectorOnMainThread:@selector(dismisser) withObject:NULL waitUntilDone:TRUE];
}
-(IBAction) shortClick:(id)sender {
    [self presentModalViewController:self.modal animated:YES];
    [NSThread detachNewThreadSelector:@selector(sleeper:) toTarget:self withObject:[NSNumber numberWithFloat:0.1f]];

}
-(IBAction) longClick:(id)sender {
    [self presentModalViewController:self.modal animated:YES];
    [NSThread detachNewThreadSelector:@selector(sleeper:) toTarget:self withObject:[NSNumber numberWithFloat:5.0f]];
}


- (void)dealloc {
    [self.modal release];
    [super dealloc];
}

@end


I prefer to do smth that can take much time in the separate thread. Then you can notify main thread(for example, you can set caller as the delegate and send a message after your calculation, or url request, or smth else has been ended) and dismiss your modal view controller there. I use performSelector:withObject:afterDelay: method if I don't know time of the calculation and want to show animation correctly.


Are you using the modal dialog to show information about the stuff you are doing? i.e. is it being used as a Please Wait... If so when you're probably better just showing a please wait dialog over the top of your current view.


Looks like it's a bug. delay your dismiss long enough with nsthread, or engage in other stupidity to work-around.


I had the same problem. I found a compromise which works for me. Basically I'm presenting the modal view without animation but dismiss it with animation. Without the animation no animation thread is being started which could cause you any trouble.

[self.navigationController presentModalViewController:self.lvc animated:NO];
//do stuff

and later on...

[self.navigationController dismissModalViewControllerAnimated:YES];

Still far away from perfect, but maybe it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消