Skip to content

Commit

Permalink
Fixed issues on iOS 8 with presenting and transparency + auto layout …
Browse files Browse the repository at this point in the history
…on action sheet items
  • Loading branch information
ipodishima committed Oct 7, 2014
1 parent 51cad70 commit c6a4e73
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
4 changes: 4 additions & 0 deletions IntentKit/Core/INKActivityViewController/INKActivityCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ - (void)updateConstraints {
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
}

+ (BOOL)requiresConstraintBasedLayout {
return YES;
}

- (void)layoutSubviews {
[super layoutSubviews];

Expand Down
46 changes: 37 additions & 9 deletions IntentKit/Core/INKActivityViewController/INKActivityPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ @interface INKActivityPresenter ()
@property (assign, nonatomic) UIModalPresentationStyle originalPresentingModalPresentationStyle;
@property (assign, nonatomic) UIModalPresentationStyle originalRootModalPresentationStyle;

@property (assign, nonatomic) BOOL originalRootProvidesPresentationContextTransitionStyle;
@property (assign, nonatomic) BOOL originalRootDefinesPresentationContext;

@property (copy, nonatomic) void (^completionBlock)();

@end
Expand Down Expand Up @@ -67,27 +70,46 @@ - (void)presentModalActivitySheetFromViewController:(UIViewController *)presenti
if (self.activity) {
[self.activity performActivityInViewController:presentingViewController];
} else if (self.activitySheet) {
self.originalRootModalPresentationStyle = UIApplication.sharedApplication.keyWindow.rootViewController.modalPresentationStyle;
UIApplication.sharedApplication.keyWindow.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;

self.presentingViewController = presentingViewController;

self.shadeView = [[UIView alloc] initWithFrame:self.presentingViewController.view.bounds];
self.shadeView.backgroundColor = [UIColor blackColor];
[self.presentingViewController.view addSubview:self.shadeView];

self.originalPresentingModalPresentationStyle = presentingViewController.modalPresentationStyle;
presentingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentingViewController presentViewController:self.activitySheet animated:NO completion:nil];
BOOL isiOS8OrSuperior = [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0f;

if (!isiOS8OrSuperior) {
self.originalRootModalPresentationStyle = UIApplication.sharedApplication.keyWindow.rootViewController.modalPresentationStyle;
UIApplication.sharedApplication.keyWindow.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;

self.originalPresentingModalPresentationStyle = presentingViewController.modalPresentationStyle;
presentingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
}
else {
self.originalRootProvidesPresentationContextTransitionStyle = UIApplication.sharedApplication.keyWindow.rootViewController.providesPresentationContextTransitionStyle;
self.originalRootDefinesPresentationContext = UIApplication.sharedApplication.keyWindow.rootViewController.definesPresentationContext;

UIApplication.sharedApplication.keyWindow.rootViewController.providesPresentationContextTransitionStyle = YES;
UIApplication.sharedApplication.keyWindow.rootViewController.definesPresentationContext = YES;
[self.activitySheet setModalPresentationStyle:UIModalPresentationOverCurrentContext];
}

[presentingViewController presentViewController:self.activitySheet animated:isiOS8OrSuperior completion:nil];

self.shadeView.alpha = 0;
CGPoint activitySheetOrigin = self.activitySheet.contentView.frame.origin;
[self.activitySheet.contentView moveToPoint:CGPointMake(self.presentingViewController.view.left, self.presentingViewController.view.bottom)];
if (!isiOS8OrSuperior) {
[self.activitySheet.contentView moveToPoint:CGPointMake(self.presentingViewController.view.left, self.presentingViewController.view.bottom)];
}

[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations: ^{
self.shadeView.alpha = 0.4;
[self.activitySheet.contentView moveToPoint:activitySheetOrigin];
if (!isiOS8OrSuperior) {
[self.activitySheet.contentView moveToPoint:activitySheetOrigin];
}
} completion:nil];
}
}
}

- (void)presentActivitySheetFromViewController:(UIViewController *)presentingViewController popoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated completion:(void (^)())completion {
Expand Down Expand Up @@ -139,6 +161,12 @@ - (void)dismissActivitySheetAnimated:(BOOL)animated {
if (self.originalRootModalPresentationStyle != -1) {
UIApplication.sharedApplication.keyWindow.rootViewController.modalPresentationStyle = self.originalRootModalPresentationStyle;
}

BOOL isiOS8OrSuperior = [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0f;
if (isiOS8OrSuperior) {
UIApplication.sharedApplication.keyWindow.rootViewController.providesPresentationContextTransitionStyle = self.originalRootProvidesPresentationContextTransitionStyle;
UIApplication.sharedApplication.keyWindow.rootViewController.definesPresentationContext = self.originalRootDefinesPresentationContext;
}

[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];

Expand Down
4 changes: 4 additions & 0 deletions IntentKit/Core/INKDefaultToggleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ - (void)updateConstraints {
}
}

+ (BOOL)requiresConstraintBasedLayout {
return YES;
}

#pragma mark - Event handlers
- (void)didTapTextLabel {
[self.toggle setOn:!self.toggle.isOn animated:YES];
Expand Down

0 comments on commit c6a4e73

Please sign in to comment.