0

テーブルセルにコンパスを作成しているので、リソース内の画像である位置から最初からやり直す画像ビューの回転に問題があります。

これは私のコードの一部です:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];

if(cellValue.direction == 0){
   cell.compass.transform = CGAffineTransformRotate(cell.compass.transform,DegreesToRadians([cellValue.fixedDirection floatValue]));
} else {
   cell.compass.transform = CGAffineTransformRotate(cell.compass.transform,DegreesToRadians([cellValue.direction floatValue]));   
}
[UIView commitAnimations];

cell.compassはUIimageViewであり、垂直方向の矢印の画像が含まれています。方向が0の場合、その程度になり、コンパスから角度を取得した後、else句に進みます。したがって、画像は、最後に回転した位置からではなく、その垂直位置から回転するようにスタートします。

最後に回転した位置を取得してそこから続行する方法

ありがとう!

4

2 に答える 2

0

removedOnCompletion = NOUIViewを回転させる代わりに、ビューのレイヤーを回転させてみてください

CALayer *layer = [cell.compass layer];
NSNumber *initRotation = [layer valueForKeyPath:@"transform.rotation"];
//CATransform3D rotationTransform = CATransform3DRotate(layer.transform, angle, 0.0, 0.0, 1.0);
//layer.transform = rotationTransform;

CABasicAnimation *animation =[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.duration = 0.5;
animation.fromValue = initRotation ;
animation.toValue = [NSNumber numberWithFloat:([initRotation floatValue] + angle)];
animation.removedOnCompletion = NO;
[layer addAnimation:animation forKey:@"transform.rotation"];
于 2011-11-30T19:44:41.177 に答える
0

私はこのような問題の解決策を見つけました:

NSLog(@"old dir %d: new dir: %d", [cellValue.oldDirection intValue], [cellValue.direction intValue]);
CABasicAnimation *animation =[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.duration = 0.5;

int oldDir = [cellValue.oldDirection intValue];
int newDir = [cellValue.direction intValue];


/// in didUpdateHeading
/// int result = 0;

/// result = fixedDir - orientation; 

/// place.oldDirection = place.direction;
/// place.direction = [NSNumber numberWithInt:result];

固定方向は、北からその場所への度数の方向です。方向は、コンパスまたはtrueHeadingからの現在の方向です。

if (oldDir*newDir < 0 && abs(abs(oldDir) - abs(newDir)) < 180) {
    oldDir = (360 + oldDir) % 360;
    newDir = (360 + newDir) % 360;
}

animation.fromValue = [NSNumber numberWithFloat:DegreesToRadians(oldDir)];
animation.toValue = [NSNumber numberWithFloat:DegreesToRadians(newDir)];


animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
[cell.compass.layer addAnimation:animation forKey:@"transform.rotation"];
float differenceAngle = [animation.toValue floatValue] - [animation.fromValue floatValue];
CATransform3D rotationTransform = CATransform3DMakeAffineTransform(CGAffineTransformRotate(cell.compass.transform,differenceAngle));

cell.compass.layer.transform = rotationTransform;

私が助けてくれたらいいのに:)

于 2011-12-07T12:41:06.483 に答える