Reputation: 13854
I am trying to debug a really weird issue in the following code:
if(condition1) {
ImageViewController* imageViewer = [[ImageViewController alloc] initWithImageData:tappedItem];
[self presentViewController:imageViewer animated:YES completion:^{
[imageViewer loadImage];
}];
}
else if(condition2) {
DocumentViewController* docViewer = [[DocumentViewController alloc] init];
[self presentViewController:docViewer animated:YES completion:nil];
}
In other words, depending on the state of condition1
and condition2
, one of two subclasses of UIViewController
will be displayed modally to the user.
In the second case all is well, but in the first the view controller is not presented with the usual animation that shows it sliding in from the bottom of the screen. Instead, after a brief delay, it just shows up all of a sudden, covering the entire screen. Another oddity is that in the dismissal animation, the image view inside the view controller is transparent.
Removing the completion block has no effect. Replacing my view controller with an instance of UIViewController
also has no effect, other than demonstrating that for some reason, animations don't work for UIViewController
instances either.
Thinking that maybe I did something wrong in viewDidLoad
etc, I tried commenting out the view load/appear methods but to no avail.
Pushing the view controller onto the nav stack is not an option because the app has a tab bar and I don't want to be visible.
update
Replacing my instance of ImageViewController
with a DocumentViewController
does result in an animation. The question now becomes: what could I have done in ImageViewController
to mess up the animation?
Upvotes: 3
Views: 2307
Reputation: 1
Setting the background color works for me in iOS 8. Also uncheck the opaque setting in the Interface Builder works!
Upvotes: 0
Reputation: 8629
It happened to me as well.. changing the background colour didn't really help. I did the following - it turns up to be quite nice:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:NO];
self.view.userInteractionEnabled = FALSE;
self.view.hidden = TRUE;
self.navigationController.navigationBar.alpha = 0;
}
-(void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:NO];
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
self.view.frame = CGRectMake(0, height, width, height);
self.view.hidden = FALSE;
[UIView animateWithDuration:0.7f animations:^{
self.view.frame = CGRectMake(0, 0, width, height);
self.navigationController.navigationBar.alpha = 1;
} completion:^(BOOL finished){
self.view.userInteractionEnabled = TRUE;
}];
}
Upvotes: 0
Reputation: 13854
I've found a solution but I still have no idea what the real cause was.
The fix was to set a background color for the view of the UIViewController
being displayed modally in its viewDidload
method e.g.
self.view.backgroundColor = [UIColor grayColor];
If I ever figure out what really happened, I will post here.
Upvotes: 4
Reputation: 344
How about presenting the view controller on the tab bar controller:
if(condition1) {
ImageViewController* imageViewer = [[ImageViewController alloc] initWithImageData:tappedItem];
[self.tabBarController presentViewController:imageViewer animated:YES completion:^{
[imageViewer loadImage];
}];
}
else if(condition2) {
DocumentViewController* docViewer = [[DocumentViewController alloc] init];
[self.tabBarController presentViewController:docViewer animated:YES completion:nil];
}
Upvotes: 0