D
D
deleted-mezhevikin2013-11-30 15:10:19
Objective-C
deleted-mezhevikin, 2013-11-30 15:10:19

Problem with PopoupViewController [video question]?

In the MainViewController, I open the PopupViewController with the presentViewController:animated:completion method.
A popupView is added to the PopupViewController (red in the video), and I make self.view transparent.
But when the animation of the controller's appearance is completed, self.view turns white, why is this happening?
+ I would like to close (dismissViewControllerAnimated) on click on PopupViewController's self.view. But if you hang a UITapGestureRecognizer with a closure on self.view, the event will fire on the tap of both the background and the popupView, but only the background needs to fire.
www.youtube.com/watch?v=sFUMs-RUtXE - video
https://github.com/nullproduction/PopupViewController - full test project code
ps I don't use nib and storyboard, I guess that may be related to this

//
//  MainViewController.m
//

#import "MainViewController.h"
#import "PopupViewController.h"

@implementation MainViewController

- (void)viewDidLoad
{
    self.view.backgroundColor = [UIColor grayColor];
    [self addPopupButton];
    [super viewDidLoad];
}

- (void)addPopupButton
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Show modal" style:UIBarButtonItemStyleBordered target:self action:@selector(showPopup)];
}

- (void)showPopup
{
    PopupViewController *popupViewController = [[PopupViewController alloc] init];
    [self presentViewController:popupViewController animated:YES completion:nil];
}

@end

//
//  PopupViewController.m
//

#import "PopupViewController.h"

@implementation PopupViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    [self addPopupView];
}

- (void)addPopupView
{
    popupView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
    popupView.backgroundColor = [UIColor redColor];
    [self.view addSubview:popupView];
}

@end

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Alexey Storozhev, 2013-12-01
@storoj

you can, for example, subscribe to the touchesEnded gestureRecognizer event as a delegate and check there if (![touch.view isDescendantOfView:popoverViewContainer]) { [self hidePopover]; }
the white background is, it seems to me, the background of the UIWindow, because the fake viewController, as I remember, does not remain under the one that was presented
at all;

A
An, 2013-12-01
@Flanker_4

As for the second one, you can always prevent the GestureRecognizer from responding to taps in some views. Examples in the documentation or here
stackoverflow.com/questions/15814697/uitapgesturerecognizer-tap-on-self-view-but-ignore-subviews
As for the first one, most likely the problem is
[self presentViewController:popupViewController animated:YES completion:nil];
As far as I remember, there are problems with animation through the presentViewController if you want to leave the old viewController underneath. stackoverflow.com/questions/7256652/why-does-presentmodalviewcontrolleranimated-turn-the-background-black/ . The idea is (and especially on the iPhone) that there should only be one active viewController per scene.
Of course you can try to play withmodalTransitionStyle
and other properties responsible for the animation style, but as practice shows, this can break in new versions of ios. You can make your custom popover animation via
[self.view addSubview:popupViewController.view]; and [UIView animationWithDuration]
But I would recommend looking towards standard controls, for example ActionSheet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question