Skip to content

Commit

Permalink
changed when view appearance events get sent for UIPopoverController'…
Browse files Browse the repository at this point in the history
…s contentViewController so that contentViewController.view has a window by the time -viewDidAppear: gets called
  • Loading branch information
joshaber committed May 26, 2011
1 parent 32b88fa commit 6ec83b6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions UIKit/Classes/UIPopoverController.m
Expand Up @@ -199,6 +199,8 @@ - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrow
[_overlayWindow setContentView:[[(UIPopoverOverlayNSView *)[UIPopoverOverlayNSView alloc] initWithFrame:overlayContentRect popoverController:self] autorelease]];
[viewNSWindow addChildWindow:_overlayWindow ordered:NSWindowAbove];

[_contentViewController viewWillAppear:animated];

// now build the actual popover view which represents the popover's chrome, and since it's a UIView, we need to build a UIKitView
// as well to put it in our NSWindow...
_popoverView = [[UIPopoverView alloc] initWithContentView:_contentViewController.view size:_contentViewController.contentSizeForViewInPopover popoverController:self];
Expand Down Expand Up @@ -266,6 +268,8 @@ - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrow
_popoverView.alpha = 1.f;
[UIView commitAnimations];
}

[_contentViewController viewDidAppear:animated];
}

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
Expand Down
6 changes: 6 additions & 0 deletions UIKit/Classes/UIPopoverView.m
Expand Up @@ -31,6 +31,7 @@
#import "UIImageView.h"
#import "UIImage+UIPrivate.h"
#import "UIPopoverController.h"
#import "UIView+UIPrivate.h"
#import <QuartzCore/QuartzCore.h>

typedef struct {
Expand Down Expand Up @@ -113,11 +114,16 @@ - (id)initWithContentView:(UIView *)aView size:(CGSize)aSize popoverController:(
_contentContainerView = [[UIView alloc] init];
_contentContainerView.layer.cornerRadius = 3;
_contentContainerView.clipsToBounds = YES;

// Suppress view appearance because otherwise they'd fire here. We want them to fire once the view is actually visible. The popover controller will handle that for us.
[_contentContainerView _setSuppressAppearanceEvents:YES];

[self addSubview:_backgroundView];
[self addSubview:_arrowView];
[self addSubview:_contentContainerView];
[_contentContainerView addSubview:_contentView];

[_contentContainerView _setSuppressAppearanceEvents:NO];

self.contentSize = aSize;
}
Expand Down
1 change: 1 addition & 0 deletions UIKit/Classes/UIView+UIPrivate.h
Expand Up @@ -39,4 +39,5 @@ extern NSString *const UIViewHiddenDidChangeNotification;
- (void)_setViewController:(UIViewController *)theViewController;
- (UIViewController *)_viewController;
- (void)_superviewSizeDidChangeFrom:(CGSize)oldSize to:(CGSize)newSize;
- (void)_setSuppressAppearanceEvents:(BOOL)suppress;
@end
1 change: 1 addition & 0 deletions UIKit/Classes/UIView.h
Expand Up @@ -118,6 +118,7 @@ typedef NSUInteger UIViewAnimationOptions;
BOOL _needsDidAppearOrDisappear;
NSMutableSet *_gestureRecognizers;
NSString *_toolTip;
BOOL _suppressAppearanceEvents;
}

+ (Class)layerClass;
Expand Down
8 changes: 6 additions & 2 deletions UIKit/Classes/UIView.m
Expand Up @@ -202,7 +202,7 @@ - (void)addSubview:(UIView *)subview

subview->_needsDidAppearOrDisappear = [self _subviewControllersNeedAppearAndDisappear];

if ([subview _viewController] && subview->_needsDidAppearOrDisappear) {
if ([subview _viewController] && subview->_needsDidAppearOrDisappear && !_suppressAppearanceEvents) {
[[subview _viewController] viewWillAppear:NO];
}

Expand Down Expand Up @@ -233,7 +233,7 @@ - (void)addSubview:(UIView *)subview

[self didAddSubview:subview];

if ([subview _viewController] && subview->_needsDidAppearOrDisappear) {
if ([subview _viewController] && subview->_needsDidAppearOrDisappear && !_suppressAppearanceEvents) {
[[subview _viewController] viewDidAppear:NO];
}
}
Expand Down Expand Up @@ -891,6 +891,10 @@ - (NSArray *)gestureRecognizers
return [_gestureRecognizers allObjects];
}

- (void)_setSuppressAppearanceEvents:(BOOL)suppress {
_suppressAppearanceEvents = suppress;
}

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
{
const BOOL ignoreInteractionEvents = !((options & UIViewAnimationOptionAllowUserInteraction) == UIViewAnimationOptionAllowUserInteraction);
Expand Down

0 comments on commit 6ec83b6

Please sign in to comment.