0

I have a UIViewController which I am using to display a video ad. As soon as the user clicks on close ad button, I dismiss the view controller, but there's a flicker soon after it gets dismissed and the parent view appears.

Here's what I'm doing in code:

@interface myController:UIViewController
@end

static myController* vc = [[myController alloc] init];

@implementation myViewController

-(void) showController
{
    [currentViewController presentViewController : self animated : NO   completion : nil];
}

-(void) hideController
{
   [self dismissViewControllerAnimated : NO completion : nil];
}

-(void) startPlaying
{
    dispatch_async(dispatch_get_main_queue(), ^{
    
    [vc showController];
     //call the method which will play the video.
});
    
}

-(void) viewClosed
{
    dispatch_async(dispatch_get_main_queue(), ^{
    
    [vc hideController];
    
});
}
@end

It's not possible to get the screenshot as it happens quickly.

I have tried making the presented view transparent as I think that after dismissal, the flicker is due to the delay after closing the video ad and then trying to dismiss the presenting view controller. It works, but after dismissal it seems like the parent view is trying to go into portrait mode instead of landscape mode. Here's a screenshot of it:

Before: Before

After: After

Olivia Stork
  • 4,660
  • 5
  • 27
  • 40
Steve
  • 58
  • 9

3 Answers3

1

Your fundamental problem is that the animation takes time.

It's not actually that easy to program for iOS .. say you call for an animation to get rid of a view controller. Fine.

You must use the completion block - you must wait for the animation to dismiss, and only then (in the completion block) carry on with other activity.

In short you must use the completion block in all cases when dismissing a view controller.

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • Thank you,Joe Blow,i think,i know,what,i might be doing wrong in my actually code now.I will give it a try.Thanks! – Steve Nov 02 '15 at 17:26
0

Try using YES for animation, and note if you are doing something in viewWillAppear, because as soon as you dismiss the presentedViewController, the parent ViewController viewWillAppear will be called.

Piyush Sharma
  • 1,891
  • 16
  • 23
  • I don't have access to the source code and hence,i don't know,what's happening in the parent view controller viewWillAppear. I have tried using YES for animation too.I have tried making my presenting view controller transparent by following this answer http://stackoverflow.com/questions/12741224/ios-modal-viewcontroller-with-transparent-background It works but then my parent view stays in a confused stage,i mean the video appears in landscape mode but it seems like after dismissal parent view tries to go into portrait mode..i will upload a snapshot to explain what i am trying to say.. – Steve Oct 27 '15 at 06:00
  • Piyush,i have added the screenshot above. – Steve Oct 27 '15 at 08:27
0

I seem to have solved my problem by using CATransition.But,i don't like the animation.I have tried creating my custom animation using UIViewControllerTransitioningDelegate and UIViewControllerAnimatedTransitioning but it didn't work because after dismissing the view controller it shows a black screen,i don't know why.. The code that is working for me is shown below...

CATransition* transition = [CATransition animation];
transition.duration = 0.05;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
UIView* containerView = self.view.window;
[containerView.layer addAnimation:transition forKey:nil]; 

[self dismissViewControllerAnimated : YES completion : nil]

Thank you!

Steve
  • 58
  • 9