将CGColorRef地址转换为UIColor

时间:2015-05-29 02:32:29

标签: ios objective-c struct uicolor cgcolor

我的应用使用Game Center将UIColor发送给其他玩家。我正在使用结构,因此UIColor表示为CGColorRef。我无法将此CGColorRef转换回另一端的UIColor,因为UIColor的方法colorWithCGColor不接收地址。

Could not connect to SeleniumWebDriver: Can't use string ("Command not found: GE
T /wd/hub/s"...) as a HASH ref while "strict refs" in use at C:/Perl/site/lib/Se
lenium/Remote/ErrorHandler.pm line 125.
 at C:/Perl/site/lib/Selenium/Remote/RemoteConnection.pm line 42.

当尝试将CGColorRef转换为UIColor时,应用程序崩溃。我将CGColorRef打印到日志中,它不是零。

typedef struct {
    MessageType messageType;
} Message;

typedef struct {
    Message message;
    CGColorRef color;
} MessageTypeColor;

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data
   fromPlayer:(NSString *)playerID {
     Message *message = (Message*)[data bytes];
     if (message->messageType == kMessageTypeColor) {
          MessageTypeColor messageTypeColor;
          [data getBytes:&messageTypeColor length:sizeof(MessageTypeColor)];
          UIColor * color = [UIColor colorWithCGColor: messageTypeColor.color];
     }
}

0 个答案:

没有答案