ボタンを押した後(360度)、UIImageViewを中心に時計回りに回転させたい...
それを行うには多くの方法があることがわかりましたが、何もうまくいきませんでした... :-)
CABasicAnimation にフレームワークを追加する必要はありますか?
UIImageView をその中心を中心に (360 度) 回転させるためのサンプル コードを誰かに教えてもらえますか?!?
前もって感謝します
ボタンを押した後(360度)、UIImageViewを中心に時計回りに回転させたい...
それを行うには多くの方法があることがわかりましたが、何もうまくいきませんでした... :-)
CABasicAnimation にフレームワークを追加する必要はありますか?
UIImageView をその中心を中心に (360 度) 回転させるためのサンプル コードを誰かに教えてもらえますか?!?
前もって感謝します
以下に示すのを聞いて、私は同じことをします......しかし、私の要件は、ビューが360度回転するtouchBeginのときです...それはあなたに役立つかもしれません.....
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
self.userInteractionEnabled=YES;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES];
[UIView commitAnimations];
[delegate changeImage:self];
}
-(void)changeImage:(DraggableImages *)selectedView
{
count++;
clickCounter++;
counterLable.text=[NSString stringWithFormat:@"%i",clickCounter];
selectedView.image=[images objectAtIndex:selectedView.tag];
if (count==1) {
firstSelectedView=selectedView;
}
if (count==2) {
self.view.userInteractionEnabled=NO;
secondSelectedView=selectedView;
count=0;
[self performSelector:@selector(compareImages) withObject:nil afterDelay:0.7];
}
}
-(void)compareImages
{
if (firstSelectedView.tag==secondSelectedView.tag)
{
matches++;
//NSLog(@"%@",matches);
Score=Score+10;
scoreLable.text=[NSString stringWithFormat:@"%d",Score];
firstSelectedView.alpha=0.5;
secondSelectedView.alpha=0.5;
self.view.userInteractionEnabled=YES;
if(matches==[images count])
{
[timer invalidate];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"Do you want to countinue?"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"YES",@"NO", nil];
[alertView show];
[alertView release];
}
}
else {
Score=Score-1;
scoreLable.text=[NSString stringWithFormat:@"%d",Score];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:firstSelectedView cache:YES];
firstSelectedView.image=[UIImage imageNamed:@"box.jpg"];
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:secondSelectedView cache:YES];
secondSelectedView.image=[UIImage imageNamed:@"box.jpg"];
[UIView commitAnimations];
firstSelectedView.userInteractionEnabled=YES;
secondSelectedView.userInteractionEnabled=YES;
self.view.userInteractionEnabled=YES;
}
}
フレームワークを追加する必要がQuartzCore
あります。詳細については、を読むことができますCABasicAnimation
。
ボタンを押すと、次のメソッドが呼び出されます。
- (void) animate{
CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
imageRotation.removedOnCompletion = NO; // Do not turn back after anim. is finished
imageRotation.fillMode = kCAFillModeForwards;
imageRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
imageRotation.duration = 1.5;
imageRotation.repeatCount = 1;
[yourImageView.layer setValue:imageRotation.toValue forKey:imageRotation.keyPath];
[yourImageView.layer addAnimation:imageRotation forKey:@"imageRotation"];
}
はい、WrightsCS が述べているように、プロジェクトに QuartzCore フレームワークが含まれている必要があります。import ステートメントを忘れないでください:
#import <QuartzCore/QuartzCore.h>