0

我希望在风景 Cocos2D 层中显示 FBLoginView。最初只是将它添加到视图中,它认为视图是纵向的,但是通过添加

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

我可以根据需要让它旋转到横向。完美的。但是,当您再次单击它以注销时,就会出现问题。出现的 ActionSheet 非常扭曲,我无法按下它上面的任何按钮(见下文)。

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

发生这种情况时,我也会在我的日志中获得一个条目;

呈现由其超级视图剪辑的操作表。某些控件可能无法响应触摸。在 iPhone 上尝试 -[UIActionSheet showFromTabBar:] 或 -[UIActionSheet showFromToolbar:] 而不是 -[UIActionSheet showInView:]。

据我所知,自定义与 FBLoginView 之间的调用并不容易。

任何想法/想法/建议都会很棒!

4

1 回答 1

0

好的,所以我找到了解决方案。

看到我正在使用 Cocos2D,在 CCLayer 上使用 UIKit 元素是困难的(即不是标准的)。因此,我必须实现 CCUIViewWrapper 并且一切正常。

这是 CCUIViewWrapper 与 Cocos2D 2.X 和 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

我希望这对其他人有帮助...

于 2013-04-30T09:30:36.897 回答