Question

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];        
} 
Was it helpful?

Solution

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;
}];

OTHER TIPS

After a week of tearing my hair out to find a solution to this I have found the offending code in the app, a little trick to round the corners of the whole app, well make it seem like the corners are rounded by adding an image there:

UIImage *bottomOverlayImage = [UIImage imageNamed:@"bottom_overlay.png"];
CALayer *bottomOverlay = [CALayer layer];
bottomOverlay.frame = CGRectMake(0, self.window.frame.size.height - 9, bottomOverlayImage.size.width, bottomOverlayImage.size.height);
bottomOverlay.contents = (id)bottomOverlayImage.CGImage;
bottomOverlay.zPosition = 1;
[self.window.layer addSublayer:bottomOverlay];

If anybody could tell me why this code would mess up the Twitter View that would be really helpful for future reference. This code was placed in the app delegate and run on first load.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top