1

iOSで一連のフレームをアニメーション化していますが、最後にテキストを表示したいと思います。この時点では、画像をアニメーション化することしかできません。CATextLayerを使用して表示しようとしているテキストが表示されません。レイヤーをビューのサブビューにする方法がわかりません。また、私が使用しようとしていたinitWithFrameメソッドは、UIViewControllerでは機能しないようです。誰か助けてもらえますか?

1)完全に機能するアニメーションコードは次のとおりです。

//setup animation
NSArray *theFrames = [NSArray array];
theFrames = [[NSArray alloc] initWithObjects:
             [UIImage imageNamed:@"frame1.png"],
             [UIImage imageNamed:@"frame2.png"],
             [UIImage imageNamed:@"frame3.png"],
             [UIImage imageNamed:@"frame4.png"],
             nil];

sceneFrames.animationImages = theFrames;
sceneFrames.animationDuration = 1;
sceneFrames.animationRepeatCount = 1;
sceneFrames.image = [theFrames objectAtIndex:theFrames.count - 1];
[sceneFrames startAnimating];

2)テキストを含むレイヤーを表示しようとしている方法は次のとおりです。ご覧のとおり、最後に表示する段階ではありません。そもそもそれをそこに持っていこうとしていて、すでに問題にぶつかっています:

// Create the new layer object
boxLayer = [[CATextLayer alloc] init];

// Give it a size
[boxLayer setBounds:CGRectMake(0.0, 0.0, 300.0, 85.0)];

// Give it a location
[boxLayer setPosition:CGPointMake(160.0, 350.0)];

// Make half-transparent red the background color for the layer
UIColor *reddish = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.75];

// Get CGColor object with the same color values
CGColorRef cgReddish = [reddish CGColor];
[boxLayer setBackgroundColor:cgReddish];

// Make it a sublayer on the view's layer
// THIS LINE DOES NOT WORK AND GIVES ME HEADACHES. It does not work without initWithFrame, which does not seem to work with UIViewController...
[[self layer] addSublayer:boxLayer];

// Create string
NSString *text2 = @"You are me.";

// Set font
[boxLayer setFont:@"Times New Roman"];

// Set font size
[boxLayer setFontSize:20.0];

[boxLayer setAlignmentMode:kCAAlignmentCenter];

// Assign string to layer
[boxLayer setString:text2];
4

1 に答える 1

1

交換

[[self layer] addSublayer:boxLayer];

[self.view.layer addSublayer:boxLayer];

また

[[self.view layer] addSublayer:boxLayer];

どちらも同じです

編集

テストした後、それは私にとって完璧に機能しました

于 2013-01-27T22:16:45.470 に答える