问题
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
回答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;
}
回答2:
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)];
}
回答3:
It would help to go into detail into your application structure, but some steps to help are:
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; }
Review other SO issues that mention this (http://stackoverflow.com/questions/2868132/shouldautorotatetointerfaceorientation-doesnt-work)
Review iOS Documentation on this and their trouble-shooting on this issue
回答4:
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...
来源:https://stackoverflow.com/questions/8395708/fbgraph-api-in-landscape-mode