私はObjectiveCとXコードを初めて使用し、UIImageViewアニメーションを少なくとも1サイクル完全に画面に表示したままにするのに問題があります。ボタンがタップされ、たくさんの保存と処理が行われるときのカスタム待機アニメーションとして使用しています。NSOpearationQueueを使用して、これらのアクションを別のスレッドで実行します。これが私のコードの最初の部分です:
私のアニメーションはViewDidLoadで定義されており、「myAnimation」と呼ばれています。これは、UIImageの配列から作成されたUIImageViewアニメーションです。すぐに非表示にして、必要なときに表示します。
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *myAnimationArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"arisprite_0000.png"],
[UIImage imageNamed:@"arisprite_0001.png"],
[UIImage imageNamed:@"arisprite_0002.png"],
[UIImage imageNamed:@"arisprite_0003.png"],
[UIImage imageNamed:@"arisprite_0004.png"],
[UIImage imageNamed:@"arisprite_0005.png"],
[UIImage imageNamed:@"arisprite_0006.png"],
[UIImage imageNamed:@"arisprite_0007.png"],
[UIImage imageNamed:@"arisprite_0008.png"],
[UIImage imageNamed:@"arisprite_0009.png"],
[UIImage imageNamed:@"arisprite_0010.png"],
[UIImage imageNamed:@"arisprite_0011.png"],
[UIImage imageNamed:@"arisprite_0012.png"],
[UIImage imageNamed:@"arisprite_0013.png"],
[UIImage imageNamed:@"arisprite_0014.png"],
[UIImage imageNamed:@"arisprite_0015.png"],
[UIImage imageNamed:@"arisprite_0016.png"],
[UIImage imageNamed:@"arisprite_0017.png"],
[UIImage imageNamed:@"arisprite_0018.png"],
[UIImage imageNamed:@"arisprite_0019.png"],
[UIImage imageNamed:@"arisprite_0020.png"],
[UIImage imageNamed:@"arisprite_0021.png"],
[UIImage imageNamed:@"arisprite_0022.png"],
[UIImage imageNamed:@"arisprite_0023.png"],
[UIImage imageNamed:@"arisprite_0024.png"],
[UIImage imageNamed:@"arisprite_0025.png"],
[UIImage imageNamed:@"arisprite_0026.png"],
[UIImage imageNamed:@"arisprite_0027.png"],
[UIImage imageNamed:@"arisprite_0028.png"],
[UIImage imageNamed:@"arisprite_0029.png"],
[UIImage imageNamed:@"arisprite_0030.png"],
[UIImage imageNamed:@"arisprite_0031.png"],
[UIImage imageNamed:@"arisprite_0032.png"],
[UIImage imageNamed:@"arisprite_0033.png"],
[UIImage imageNamed:@"arisprite_0034.png"],
[UIImage imageNamed:@"arisprite_0035.png"],
[UIImage imageNamed:@"arisprite_0036.png"],
[UIImage imageNamed:@"arisprite_0037.png"],
nil];
myAnimation.animationImages = myAnimationArray;
myAnimation.animationDuration = 2.5;
[myAnimation.layer setBorderColor:[[UIColor blackColor] CGColor]];
[myAnimation.layer setBorderWidth:2.0];
[self.view addSubview:myAnimation];
[myAnimation setHidden:YES];
...
...
...
}
-(IBAction)saveToYYY:(id)sender
{
// hide current view and show save screen
[self showAnimatedSaveScreen];
// show the saving screen
[self.view bringSubviewToFront:savingBackgroundView];
[self.view bringSubviewToFront:savingText];
[self.view bringSubviewToFront:myAnimation];
/* Operation Queue init */
NSOperationQueue *queue = [NSOperationQueue new];
/* Create our NSInvocationOperation to call save code, passing in nil */
NSInvocationOperation *saveToYYYOperation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(saveToYYYWithOperation)
object:nil];
NSInvocationOperation *saveToXXXOperation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(saveToXXXWithOperation)
object:nil];
/* Add the operation to the queue */
[saveToXXXOperation addDependency:saveToYYYOperation];
[queue addOperation:saveToYYYOperation];
[queue addOperation:saveToXXXOperation];
}
次に、最後のキュー操作で
-(void)saveToXXXWithOperation
{
...
a bunch of processing
...
[self performSelectorOnMainThread:@selector(hideAnimatedSaveScreen) withObject:nil waitUntilDone:YES];
}
これらの保存操作が速すぎる場合、特にiPadで、myAnimationが2.5の期間を終了できないことを除いて、すべてが正常に機能しているようです。アニメーションを非表示にする前に、少なくとも1回は再生したいと思います。これを実装する方法はありますか?