无法让 UIImage 在 cs193p 中的超级卡示例中绘制到卡前面



我正在进行iTunesu CS193P课程。如SuperCard所示,我正在尝试获取以下代码将图像绘制到卡片前面,但是由于某种原因,该图像没有被绘制到Uiview。一些帮助将不胜感激。

//using an image for the face of the card, i'm going to look it up to see if it exists
if (self.faceUp){
    UIImage *faceImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@", [self rankAsString], self.suit]];
    NSLog(@"the faceImage is %@", faceImage);
    if (faceImage) {
    //i'm defining where and how big this is going to be   // the 1.0 - the scale factor, basically means 90% of the card size that i'm going to use
        CGRect imageRect =CGRectInset(self.bounds,
                                  self.bounds.size.width * (1.0-self.faceCardScaleFactor),
                                  self.bounds.size.height * (1.0-self.faceCardScaleFactor));
        [faceImage drawInRect:imageRect];
    } else {
        [self drawPips];
    }

我尝试了以下内容,并使用词典使它上班:

if (self.faceUp){
    //renamed some png pictures and imported them into the Images.xcassets folder
    NSDictionary *cardImages=@{@"J":@"jack.png",@"Q":@"queen.png",@"K":@"king.png"};
    UIImage *faceImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@", [cardImages        valueForKey:[self rankAsString]]]];
    if (faceImage) {. . . .

,但我仍然不确定为什么较早的代码没有拉出图像。例如,图像中所示的心脏国王图像的名称为" k♥"。当我从斯坦福网站下载代码时,我也无法将其绘制到视图中,所以我想知道其他人是否遇到了这个问题。

谢谢。

我也有同样的问题。我认为我选择了不同的符号,或者是某种编码问题的字符。解决了我的问题是用我插入的相同符号(副本)重命名图像的原因。另一个决定是从图像文件名中获取相同的字符并在代码中使用它。

我也有同样的问题。这是因为该西装如果图像名称具有不同的字符,则与您在代码中使用的西装设置不同。我将所有图像名称重命名为lastep,它起作用。

+ (NSArray *)validSuits
{
    return @[@"♥",@"♦",@"♠",@"♣"];
}

最新更新