나는 앱을 가지고 있으며 주사위 애니메이션을 재현해야합니다. 오지가 굴러 질 때마다 X 축과 그의 회전에 대한 그의 위치를 약간 변경해야합니다.같은 시간에보기의 위치를 회전하고 변경 하시겠습니까?
주사위는 UIView
의 내부에 UIButton
이며 16 픽셀이 더 큽니다. 사용자가 회전 할 때 회전하는 애니메이션을 만들고 동시에 X보기 값의 변화를 애니메이션으로 만듭니다. 애니메이션이 끝나면 무작위 정지 위치를 고치려고합니다.
더 잘 이해하려면 내 코드를보십시오.
이 내 회전 애니메이션입니다 :
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
animation.duration = 0.2;
animation.repeatCount = 2;
[dice.layer addAnimation:animation forKey:@"SpinAnimation"];
int min = -20;
int maxim = 20;
int rndValue = min + arc4random() % (maxim - min);
// Here I change x value;
CGRect rct = dice.superview.frame;
rct.origin.x = n + rndValue;
rct.size.width = dice.superview.bounds.size.width;
rct.size.height = dice.superview.bounds.size.height;
[UIView animateWithDuration:0.4 animations:^{
dice.superview.frame = rct;
}completion:^(BOOL finished){
//Here, after the animation is done, i want to put a random rotation value.
float degrees = arc4random() % 30;
dice.superview.layer.anchorPoint = CGPointMake(0.5, 0.5);
dice.superview.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);
}];
내 문제는, (내가 마우스를 가져 가면 첫 번째 예상)에 오지 (너무보기) 작아 질 때마다보다보기 프레임의 크기가 변화하고 있기 때문에 내가 할 수있는 문제 또는 다른 해결책을 찾지 못했습니다. PS :이 중 하나만 사용하면 (회전 또는 변경 X 축 값) 오이스는 같은 크기를 유지합니다.
나는 이미 온라인으로 많이 검색하지만 나에게는 도움이되지 않습니다. 누구든지 아이디어가 있으십니까? 고마워요!