简体   繁体   English

FBLoginView方向

[英]FBLoginView orientation

I wish to show the FBLoginView in a landscape Cocos2D layer. 我想展现FBLoginView中的一道风景cocos2d的层。 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). 出现的ActionSheet是非常扭曲的,我不能按任何按钮就可以了(见下文)。

http://www.dansinclair.co.uk/SO/FBLoginView_error.png 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:]. 在iPhone上尝试 - [UIActionSheet showFromTabBar:]或 - [UIActionSheet showFromToolbar:]代替 - [UIActionSheet showInView:]。

To my knowledge, it's not easy to customise the calls to and from the FBLoginView. 据我所知,这是不容易定制和从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. 看到我正在使用Cocos2D时,很难(即非标准)在CCLayer上使用UIKit元素。 Thus, I had to implement CCUIViewWrapper and all is working fine. 因此,我必须实现CCUIViewWrapper,并且一切正常。

Here's my code for CCUIViewWrapper to work with Cocos2D 2.X and ARC; 这是CCUIViewWrapper与Cocos2D 2.X和ARC一起使用的代码。

CCUIViewWrapper.h 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 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... 我希望这可以帮助其他人...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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