Tôi có một lớp con CALayer
với phao animAngle
làm thuộc tính được đánh dấu là @dynamic
. Tôi đã triển khai các phương thức actionForKey
, initWithLayer
, needsDisplayForKey
và drawInContext
cho lớp con. Định nghĩa cho actionForKey
như sauLớp con CALayer không hoạt ảnh để thay đổi thuộc tính
- (id<CAAction>)actionForKey:(NString *)event {
if([event isEqualToString:@"animAngle"]) {
return [self animationForKey:event];
}
return [super actionForKey:event];
}
Và
- (CABasicAnimation *)animationForKey:(NSString *)key
{
NSString *animValue = [[self presentationLayer] valueForKey:key];// Logs as 0
CABasicAnimation *anim;
if([key isEqualToString:@"animAngle"]) {
anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
anim.repeatCount = HUGE_VAL;
anim.autoreverses = YES;
//anim.fromValue = [[self presentationLayer] valueForKey:key]; // setting animation value from layer property as in here does not work.
anim.fromValue = [NSNumber numberWithFloat:0.5f]; // This works
}
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.duration = 0.11;
return anim;
}
Trong someother lớp:
myCASublayer.animAngle = 0.5f;
Bằng cách nào đó CABasicAnimation
được trả lại không có khả năng sử dụng đúng lớp "animAngle
" bất động sản. Tôi có thể làm gì sai ở đây?
Một được gọi là 'animAngle' khác là' wiggleAngle' –
@RobvanderVeer: Xin lỗi đó là một lỗi đánh máy. AnimAngle của nó. – rawatm
@ basstrekerk87, sao chép/dán tốt hơn lần sau, tiết kiệm lỗi! Bạn biết bạn không thực sự phải thụt lề mã bằng tay? Sử dụng nút hoặc bắt đầu với 3 backquotes (') –