简体   繁体   中英

FBLoginView orientation

I wish to show the FBLoginView in a landscape Cocos2D layer. Originally with just having it added to the view it was thinking the view was portrait, but by adding

[loginview setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];

I was able to have it rotate to landscape as I needed. Perfect. However, the problem arises when you click on it again to Log Out. The ActionSheet that appears is very warped and I can't press any buttons on it (see below).

http://www.dansinclair.co.uk/SO/FBLoginView_error.png

I also get an entry in my log when this happens;

Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].

To my knowledge, it's not easy to customise the calls to and from the FBLoginView.

Any ideas/thoughts/advice would be great!

Ok, so I've found the solution.

Seeing as I'm using Cocos2D it was difficult (ie not standard) to use a UIKit element on the CCLayer. Thus, I had to implement CCUIViewWrapper and all is working fine.

Here's my code for CCUIViewWrapper to work with Cocos2D 2.X and ARC;

CCUIViewWrapper.h

#import "cocos2d.h"

@interface CCUIViewWrapper : CCSprite
{
UIView *uiItem;
float rotation;
}
@property (nonatomic, retain) UIView *uiItem;

+ (id) wrapperForUIView:(UIView*)ui;

- (id) initForUIView:(UIView*)ui;
- (void) updateUIViewTransform;
@end

CCUIViewWrapper.m

#import "CCUIViewWrapper.h"

@implementation CCUIViewWrapper

@synthesize uiItem;

+ (id) wrapperForUIView:(UIView*)ui
{
return [[self alloc] initForUIView:ui];
}

- (id) initForUIView:(UIView*)ui
{
if((self = [self init]))
{
    self.uiItem = ui;
    return self;
}
return nil;
}

-(void)setParent:(CCNode *)parent {
if(parent == nil) {
    [uiItem removeFromSuperview];
} else if(uiItem != nil) {
    [[[CCDirector sharedDirector] view] addSubview:uiItem];
}
[super setParent:parent];
}

-(void)updateUIViewTransform {
float thisAngle, pAngle;
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, [[CCDirector sharedDirector] winSize].height);

for(CCNode *p = self; p != nil; p = p.parent) {
    thisAngle = CC_DEGREES_TO_RADIANS(p.rotation);
    if(p.ignoreAnchorPointForPosition)
        transform = CGAffineTransformTranslate(transform, p.anchorPointInPoints.x, p.anchorPointInPoints.y);

    if(p.parent != nil) {
        pAngle = CC_DEGREES_TO_RADIANS(p.parent.rotation);

        transform = CGAffineTransformTranslate(transform,
                                               (p.position.x * cosf(pAngle))+(p.position.y * sinf(pAngle)),
                                               (-p.position.y * cosf(pAngle))+(p.position.x * sinf(pAngle)));
    }
    else {
        transform = CGAffineTransformTranslate(transform, p.position.x, -p.position.y);
    }

    transform = CGAffineTransformRotate(transform, thisAngle);
    transform = CGAffineTransformScale(transform, p.scaleX, p.scaleY);
    transform = CGAffineTransformTranslate(transform, -p.anchorPointInPoints.x, -p.anchorPointInPoints.y);
}

[uiItem setTransform:transform];
}

- (void) setVisible:(BOOL)v
{
[super setVisible:v];
[uiItem setHidden:!v];
}

- (void) setRotation:(float)protation
{
[super setRotation:protation];
[self updateUIViewTransform];
}

- (void) setScaleX:(float)sx
{
[super setScaleX:sx];
[self updateUIViewTransform];
}

- (void) setScaleY:(float)sy
{
[super setScaleY:sy];
[self updateUIViewTransform];
}

- (void) setOpacity:(GLubyte)opacity
{
[uiItem setAlpha:opacity/255.0];
[super setOpacity:opacity];
}

- (void) setContentSize:(CGSize)size
{
[super setContentSize:size];
uiItem.frame    = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
uiItem.bounds   = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
}

- (void) setAnchorPoint:(CGPoint)pnt
{
[super setAnchorPoint:pnt];
[self updateUIViewTransform];
}

- (void) setPosition:(CGPoint)pnt
{
[super setPosition:pnt];
[self updateUIViewTransform];
}

@end

I hope this helps someone else...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM