Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SLComposeViewController Views sent to back in app and becomes unresponsive

I have a button in my app to bring up an SLComposeViewController for use with Twitter. When the view is presented it animates in correctly and the disappears. I have found that when it disappears it is sent to the back of the current view and I have no way to bring it back. I have tried manually sending all the views on top to the back in code with no luck. I feel there is something fundamentally wrong with my app for this to happen as this behaviour is seen at any level to the Navigation Controller in the app. Below is a screenshot of the SLComposeViewController being the Navigation Bar in the app, I made the ViewController's view have an Alpha value of 0.0f to illustrate my point:

enter image description here

I really don't know what is going on here and any help will be greatly appreciated. The code I am using to present the SLComposeViewController is pretty standard and I have tested it in another app and works fine:

NSString *message = [NSString stringWithFormat:@"#%@", [twitterInfo objectForKey:@"hashtag"]];

if ([appDelegate isSocialAvailable]) {
    // code to tweet with SLComposeViewController
    SLComposeViewController *twitter = [[SLComposeViewController alloc] init];
    twitter = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
    [twitter setInitialText:[NSString stringWithFormat: @"%@", message]];
    [self presentViewController:twitter animated:YES completion:nil];        
} 
like image 749
SamRowley Avatar asked Nov 12 '22 07:11

SamRowley


1 Answers

Thanks for posting this, I had the same thing happen because I was adding a CAShapeLayer to my window for a gradient effect. Your post helped me figure out that this was the problem.

It looks like this is happening is because they are adding their view's layer to the window's sublayers--at index 0 I might add! This is contrary to what you would expect, which is that they would add their view as a subview to the presenting view controller's view.

They must have just thought that people don't add layers to their window and they want to make sure they are not competing with your view stack. Why they would put it into index 0 must only be because someone is in the habit of doing -[CALayer insertLayer:layer atIndex:0] I suppose.

I'm not certain but I am guessing this could be the case with any modal view controller.

The fix is pretty simple:

[viewController presentViewController:facebookViewController
                             animated:YES
                           completion:^{
    facebookViewController.view.layer.zPosition = 1000;
}];
like image 147
garafajon Avatar answered Nov 15 '22 06:11

garafajon