안녕하세요, 모션 이후에 재생되는 애니메이션이있는 앱을 만들고 비어있는 상태가되면 애니메이션에서 사운드 재생이 끝나면 코드에 상태가 필요합니다. 사운드 코드가있어서 그냥해야합니다. 그것을 설명하는 방법을 알고, [animation startanimating]
및 [animation stopanimating]
, [audioplayer play]
및 [audioplayer stop]
과 같은 코드를 사용하고 있습니다. 고맙습니다 초보자입니다. 제발 쉽게가주세요 :)애니메이션의 종료 상태를 어떻게 알 수 있습니까?
답변
완료 콜백이있는 블록을 사용하도록 코드를 변환 할 수 있습니다. this 답변 예. 예와
편집 :
이의이 애니메이션을 적용 할 뷰가 myView
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
myView.alpha = 0; // a fade out animation
}
completion:^(BOOL finished)
{
[audioPlayer play];
// whatever else
}
];
이라고 가정 해 봅시다이 당신이 시도 무엇인가? 더 많은 실제 코드를 게시 할 수 있습니까? 애니메이션 및 콜백 전체를 어떻게 처리하는지 확인할 수 있습니다.
안녕하세요, 내가 말했듯이 나는 총 초보자입니다. 그 일을 시도했으나 제대로 작동하지 않았기 때문에 작동하지 않았습니다. – user1483652
이것이 완료된 방법입니다.^(BOOL 완료) { [audioPlayer play]; play.hidden = 0; }; – user1483652
좋아요. 붙여 넣기 저장소를 만들고 여기에 몇 분 후에 링크를 넣으면 전체 코드가 나타납니다. – user1483652
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
//animation block
// perform animation here
}
completion:^(BOOL finished){
// play sound here
[audioPlayer play]
}];
애니메이션 코드를이 코드에 넣어야합니까? – user1483652
이 코드는 애니메이션 용이므로 ... 애니메이션을 수행하고 싶을 때 작성하십시오. –
CAKeyFrameAnimation
을 사용하고 싶을 것입니다. 이렇게하면 개별 프레임 시간이있는 일련의 이미지를 통해 애니메이션 할 수 있습니다. 및은 애니메이션이 끝나면 UIImageView
으로 애니메이션이 적용되지 않는 위임 통지를받습니다.
일부 샘플 코드
당신은 (ARC를 가정) 시작하기 :// create an animation overlay view to display and animate our image frames
UIView *animationView = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:animationView];
// using 4 images for the example
NSArray *values = [NSArray arrayWithObjects:(id)[[UIImage imageNamed:@"Image1.png"] CGImage],
(id)[[UIImage imageNamed:@"Image2.png"] CGImage],
(id)[[UIImage imageNamed:@"Image3.png"] CGImage],
(id)[[UIImage imageNamed:@"Image4.png"] CGImage],
nil];
// change the times as you need
NSArray *keyTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.25],
[NSNumber numberWithFloat:0.50],
[NSNumber numberWithFloat:1.0],nil];
// animating the contents property of the layer
CAKeyframeAnimation *keyframe = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
keyframe.values = values;
keyframe.keyTimes = keyTimes;
keyframe.calculationMode = kCAAnimationLinear;
keyframe.duration = 1.0; // 1 second, can be whatever you want, obviously
keyframe.delegate = self;
keyframe.removedOnCompletion = NO;
keyframe.fillMode = kCAFillModeForwards;
// "user defined string" can be whatever you want and probably should be constant somewhere in
// your source. You can use this same key if you want to remove the animation
// later using -[CALayer removeAnimationForKey:] on the animationView's layer
[animationView.layer addAnimation:keyframe forKey:@"user defined string"];
그런 다음, 다른 곳에서, 당신의 대리자 메서드를 구현 :
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)finished
{
if (finished) {
// play music
}
}
포스트 전체 코드 바랍니다. –
http://pastebin.com/x9m9qXcb – user1483652
애니메이션으로 정확히 무엇을하려고합니까? 매초마다 이미지를 뒤집겠습니까? –