Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple type of root view controllers for content action #2

Merged
merged 5 commits into from
May 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions BLEKit/Actions/BLEContentAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,41 @@ - (BOOL)canPerformBeaconAction:(BLETrigger *)trigger forState:(BLEActionState)st

#pragma mark - Private

+ (UIViewController *)visibleViewControllerFrom:(UIViewController *) vc {
if ([vc isKindOfClass:[UINavigationController class]]) {
return [BLEContentAction visibleViewControllerFrom:[((UINavigationController *) vc) visibleViewController]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that about topViewController here ?

} else if ([vc isKindOfClass:[UITabBarController class]]) {
return [BLEContentAction visibleViewControllerFrom:[((UITabBarController *) vc) selectedViewController]];
} else {
if (vc.presentedViewController) {
return [BLEContentAction visibleViewControllerFrom:vc.presentedViewController];
} else {
UIViewController *topMostVC = vc;
while (topMostVC.childViewControllers.count > 0) {
topMostVC = [topMostVC.childViewControllers lastObject];
}
return topMostVC;
}
}
}

- (UIViewController *)topViewController
{
UIViewController *vc = [[[UIApplication sharedApplication] keyWindow] rootViewController];
UIViewController *topMostVC = vc;
while (topMostVC.childViewControllers.count > 0) {
topMostVC = [topMostVC.childViewControllers lastObject];
}
return topMostVC;

return [BLEContentAction visibleViewControllerFrom:vc];
}

- (void) showContentView
{
BLEContentActionIsVisible = YES;

self.contentViewController = [[BLEContentViewController alloc] initWithURL:self.url action:self];
self.contentViewController.view.frame = [UIApplication sharedApplication].keyWindow.bounds;
self.contentViewController.view.frame = [UIApplication sharedApplication].keyWindow.rootViewController.view.bounds;
self.contentViewController.delegate = self;

UIViewController *topViewController = [self topViewController];

// move topViewController
[topViewController addChildViewController:self.contentViewController];
[topViewController.view addSubview:self.contentViewController.view];
Expand Down
4 changes: 3 additions & 1 deletion BLEKit/Actions/BLEContentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ - (void)viewDidLoad

CGFloat yPos = self.view.frame.origin.y > 64 ?: 64.0;
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, yPos, self.view.frame.size.width, self.view.frame.size.height - yPos)];
self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.webView];

// Toolbar
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
[closeButton setFrame:CGRectMake(0, 20, self.view.frame.size.width, 44)];
closeButton.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[closeButton setFrame:CGRectMake(0, 60, self.view.frame.size.width, 44)];
[closeButton setTitle:NSLocalizedString(@"Close",nil) forState:UIControlStateNormal];
[closeButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[closeButton addTarget:self action:@selector(closeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
Expand Down