1

I am using FbGraph API for facebook integration. Everything is working fine, but the problem is that the FbGraph API does not rotate in landscape view.

I also used the shouldAutorotateToInterfaceOrientation to YES, and i tried to put a breakpoint in didRotateFromInterfaceOrientation.

It is never being called. I am really stuck into this. pls help

Ajeet Pratap Maurya
  • 4,244
  • 3
  • 28
  • 46
  • Are you confusing Facebook API with iOS Development? The FB Graph API library that you can download for iOS is an SDK for interacting with Facebook's Graph API. Your device and the app that listens to changes in device state (i.e. within your ViewController) are what will listen for those events. – Dominic Tancredi Dec 06 '11 at 05:30
  • i am using FbGraph API in my iOS app, and it works just fine, the problem is only with the orientation. :( – Ajeet Pratap Maurya Dec 06 '11 at 05:31

4 Answers4

1

I use below and its work fine,

1) post notification in - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation method of view from which you use FBGraph

2)

- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{

     [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"CHANGE_ORIENTATION" object:orientation]];

}

3) In the FBGraph

-(void)authenticateUserWithCallbackObject:(id)anObject andSelector:(SEL)selector andExtendedPermissions:(NSString *)extended_permissions {

    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self selector:@selector(shouldAutorotateToInterfaceOrientation:)
               name:@"CHANGE_ORIENTATION"
             object:nil];
   -----------
 -------
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(NSNotification *)notofication

{

    if([notofication.object isEqualToString:@"LEFT"])
    {
        CGAffineTransform newTransform;
        newTransform = CGAffineTransformMakeRotation(M_PI * 270 / 180.0f);
        webView.transform = newTransform;
        [webView setFrame:CGRectMake(12, 0, 320, 480)];
        NSLog(@"LEFT");
    }
    else if([notofication.object isEqualToString:@"RIGHT"])
    {
        CGAffineTransform newTransform;
        newTransform = CGAffineTransformMakeRotation(M_PI * 90 / 180.0f);
        webView.transform = newTransform;
            [webView setFrame:CGRectMake(0, 0, 305, 480)];
        NSLog(@"RIGHT");
    }
    else if([notofication.object isEqualToString:@"PORTRAIT"])
    {
        CGAffineTransform newTransform;
        newTransform = CGAffineTransformMakeRotation(M_PI * 360 / 180.0f);
        webView.transform = newTransform;
            [webView setFrame:CGRectMake(0, 12, 320, 480)];
        NSLog(@"PORTRAIT");
    }
    else if([notofication.object isEqualToString:@"DOWN"])
    {
        CGAffineTransform newTransform;
        newTransform = CGAffineTransformMakeRotation(M_PI * 180 / 180.0f);
        webView.transform = newTransform;
            [webView setFrame:CGRectMake(0, 0, 320, 465)];
        NSLog(@"DOWN");
    }
    return YES;
}
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
iBhavik
  • 663
  • 11
  • 28
1

Am using the following method, and its working fine.

Use the following code in the view, in which you are going to use fbgraph.

@i-bhavik thanks for the core idea dude.

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {

    NSLog(@"left");

    [self leftOrienation];

    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
    [self rightOrientation];
    NSLog(@"right");
    }
    else
    {

    }

    //  Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||      interfaceOrientation == UIInterfaceOrientationLandscapeRight);

    }

here i have initialized FbGraph as fbGraph.

   -(void)leftOrienation
   {
   CGAffineTransform newTransform;
   newTransform = CGAffineTransformMakeRotation(M_PI * 270 / 180.0f);
   fbGraph.webView.transform = newTransform;
   [fbGraph.webView setFrame:CGRectMake(0, 0, 768, 1024)];

   }

   -(void)rightOrientation
   {
   CGAffineTransform newTransform;
   newTransform = CGAffineTransformMakeRotation(M_PI * 90 / 180.0f);
   fbGraph.webView.transform = newTransform;
   [fbGraph.webView setFrame:CGRectMake(0, 0, 768, 1024)];

    }
Veera Raj
  • 1,562
  • 1
  • 19
  • 40
0

I solved this problem myself. instead using the UIView provided by FBGraph API I just made my own UIViewController and implemented that API in that view controller. and the next moment the problem was solved...

Ajeet Pratap Maurya
  • 4,244
  • 3
  • 28
  • 46
0

It would help to go into detail into your application structure, but some steps to help are:

  1. Set all ViewControllers you're using that need to listen to the rotation with the method defined (note this will rotate for ALL orientations, so look at the documentation on how to support Portrait or Landscape):

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
         return YES;
    }
    
  2. Review other SO issues that mention this (http://stackoverflow.com/questions/2868132/shouldautorotatetointerfaceorientation-doesnt-work)

  3. Review iOS Documentation on this and their trouble-shooting on this issue

Maulik
  • 19,348
  • 14
  • 82
  • 137
Dominic Tancredi
  • 41,134
  • 7
  • 34
  • 50
  • I used shouldAutorotate in all view controller but no luck. What is happening now is that i have a modalview and in that when we click on fb share it calls class A which in turn class the FbGraph API. and in the API the is no xib. it just shows a UIView which get shown. – Ajeet Pratap Maurya Dec 06 '11 at 06:16
  • It's not the UIView that's not rotating, it's the UIViewController that's listening for that event and telling the views that they can rotate. Can you rotate your app when you are in the previous view controllers? Are you trying to rotate that UIView? Subviews respect the settings of their VC. If you're in a NavController or TabBarController, make sure you set it there as well. – Dominic Tancredi Dec 06 '11 at 13:59