gpt4 book ai didi

objective-c - 从结果类型为 'UIView *_strong' 的函数返回 'CardCreationClass *' 的不兼容指针类型

转载 作者:搜寻专家 更新时间:2023-10-30 20:21:01 25 4
gpt4 key购买 nike

我收到上述错误,但我不确定如何修复它,有人能告诉我为什么会收到此错误以便我修复它吗?

代码本身可以工作并将图像(文本层除外)绘制到屏幕上,所以我只想消除错误。我已经搜索过堆栈溢出并找到了“casting”,但在尝试这种技术后错误仍然存​​在。

我认为是因为我正在使用这些方法

[CardElementsCreationClass drawHeart]

[CardElementsCreationClass drawValueWithSuit:suit AndValue:value]

我的.m

#import "CardCreationClass.h"

@implementation CardCreationClass

//--------------------
//Create a card
//
+ (UIView *) newPlayingCardWithSuit:(NSString *)suit
AndValue:(NSString *)value {
//Create playing card UIVIew
CGRect playingCardBounds = CGRectMake(100, 50, 100, 200);
//CGPoint playingCardPosition = CGPointMake(100, 50);

UIView* playingCard = [[UIView alloc] initWithFrame:playingCardBounds];

//CREATE BACK OF CARD
//

//CREATE FRONT OF CARD
CALayer* front = [CALayer layer];

//Determine suit
CAShapeLayer *cardSuitShapeLayer;

if ([suit isEqualToString:@"heart"]) {
cardSuitShapeLayer = [CardElementsCreationClass drawHeart];
}

[front addSublayer:cardSuitShapeLayer];

//Determine value
CATextLayer *cardValueTextLayer = [CardElementsCreationClass drawValueWithSuit:suit AndValue:value];

[front addSublayer:cardValueTextLayer];

//Add layers to card
[playingCard.layer addSublayer:front];

NSLog(@"Type = %@", [playingCard class]);

//Return - **ERROR HAPPENS HERE**
return playingCard;
}

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}

- (void)drawRect:(CGRect)rect {
// Drawing code
[CardCreationClass newPlayingCardWithSuit:@"heart" AndValue:@"A"];
}

@end

绘制代码

#import "CardElementsCreationClass.h"

@implementation CardElementsCreationClass

//--------------------
//HEARTS
//
+ (CGMutablePathRef)newHeartPath {
//Declare
CGMutablePathRef heartPath = CGPathCreateMutable();

//Create shape
CGPathAddEllipseInRect(heartPath, NULL, CGRectMake(0, 0, 20, 20));
CGPathAddEllipseInRect(heartPath, NULL, CGRectMake(20, 0, 20, 20));

CGPathMoveToPoint(heartPath, NULL, 37.5, 16.5);

CGPathAddLineToPoint(heartPath, NULL, 37.5, 16.5);
CGPathAddLineToPoint(heartPath, NULL, 20, 37.5);
CGPathAddLineToPoint(heartPath, NULL, 2.5, 16.5);
CGPathAddLineToPoint(heartPath, NULL, 20, 10);

CGPathCloseSubpath(heartPath);

//Return
return heartPath;
}

+ (CGMutablePathRef)newHeartHighlightPath {
//Declare
CGMutablePathRef heartHighlightPath = CGPathCreateMutable();

//Create hightlight
CGPathAddArc(heartHighlightPath, NULL, 0, 0, 7, -(110 * M_PI) / 180, -(0 * M_PI), NO);

CGPathAddLineToPoint(heartHighlightPath, NULL, 4, 0);

CGPathAddCurveToPoint(heartHighlightPath, NULL, 4, -7, 0, -7, 0, -7);

//Return
return heartHighlightPath;
}

+ (CAShapeLayer*)drawHeart {
CAShapeLayer* heartShapeLayer = [CAShapeLayer layer];

//Context
CGContextRef context = UIGraphicsGetCurrentContext();

//Declare
CGMutablePathRef heartPath = [self newHeartPath];

/*CGPathAddArc(heartPath, NULL, 10, 10, 10, M_PI, 0, false); // Left hump
CGPathAddArc(heartPath, NULL, 30, 10, 10, M_PI, 0, false); // Right hump
CGPathAddLineToPoint(heartPath, NULL, 20, 37.5); // Pointy end

CGPathCloseSubpath(heartPath);*/

//Line
CGContextSetLineWidth(context, 8.0);
CGContextSetLineJoin(context, kCGLineJoinRound);

//Colour shape
CGContextSetCMYKStrokeColor(context, 0.17, 1, 1, 0.07, 1);
CGContextSetCMYKFillColor(context, 0.07, 1, 1, 0.01, 1);

//Draw shape
CGContextTranslateCTM(context, 4, 4);

CGContextAddPath(context, heartPath);
CGContextDrawPath(context, kCGPathStroke);

CGContextAddPath(context, heartPath);
CGContextDrawPath(context, kCGPathFill);

//Colour highlight
CGContextSetCMYKFillColor(context, 0, 0, 0, 0, 0.3);

//Left highlight
CGMutablePathRef heartHightlightLeft = [self newHeartHighlightPath];

//Draw highlight
CGContextTranslateCTM(context, 10, 9);

CGContextAddPath(context, heartHightlightLeft);
CGContextDrawPath(context, kCGPathFill);

//Right highlight
CGMutablePathRef heartHightlightRight = [self newHeartHighlightPath];

//Draw hightlight
CGContextTranslateCTM(context, 20, 0);

CGContextAddPath(context, heartHightlightRight);
CGContextDrawPath(context, kCGPathFill);

//Attach
heartShapeLayer.path = heartPath;

//Release
CGPathRelease(heartPath);
CGPathRelease(heartHightlightLeft);
CGPathRelease(heartHightlightRight);

//Return
return heartShapeLayer;
}

//--------------------
//VALUES
//
+ (CATextLayer*)drawValueWithSuit:(NSString *)suit
AndValue:(NSString *)value {
CATextLayer* valueTextLayer = [CATextLayer layer];

valueTextLayer.string = value;
valueTextLayer.borderWidth = 2.0;
valueTextLayer.borderColor = [UIColor blackColor].CGColor;

valueTextLayer.bounds = CGRectMake(0, 0, 50, 50);

//Determine colour
if ([suit isEqualToString:@"heart"] || [suit isEqualToString:@"diamond"]) {
valueTextLayer.foregroundColor = [UIColor redColor].CGColor;
} else if ([suit isEqualToString:@"club"] || [suit isEqualToString:@"spade"]) {
valueTextLayer.foregroundColor = [UIColor blackColor].CGColor;
}

//Return
return valueTextLayer;
}

@end

最佳答案

只需重命名方法

+ (UIView *) newPlayingCardWithSuit:(NSString *)suit
AndValue:(NSString *)value

不以单词 new 开头的内容。例如:

+ (UIView *) playingCardWithSuit:(NSString *)suit
andValue:(NSString *)value

关于objective-c - 从结果类型为 'UIView *_strong' 的函数返回 'CardCreationClass *' 的不兼容指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11071295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com