// tập tin tiêu đề cho các lớp thẻRắc rối với CAAnimation
#import "OWCardView.h"
@implementation OWCardView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.layer.contents = (id) [UIImage imageNamed:@"4.png"].CGImage;
self.layer.shadowColor = [UIColor whiteColor].CGColor;
self.layer.shadowOpacity = 0.3;
}
return self;
}
- (void) moveCard:(float)xPoint along:(float)yPoint
{
CGRect someRect = CGRectMake(xPoint, yPoint, 72, 96);
[UIView animateWithDuration: 3.5
delay: 0.3
options: UIViewAnimationCurveEaseOut
animations: ^{ self.frame = someRect;}
completion: ^(BOOL finished) { }];
}
@end
// part of the Implementation in the view controller's viewDidLoad
[...]
CGRect myImageRect = CGRectMake(20.0f, 20.0f, 72.0f, 96.0f);
// myCard is a property of the viewController
self.myCard = [[OWCardView alloc] initWithFrame:myImageRect];
[self.view addSubview:self.myCard];
[self.myCard moveCard: 240 along: 355]; // First call
[self.myCard moveCard: 50 along: 355]; // Second call
[self.myCard moveCard: 50 along: 50]; // Third call
[...]
Vấn đề: Chỉ có tin nhắn cuối cùng để moveCard trong viewController được thực hiện; các cuộc gọi đầu tiên và thứ hai không thực thi. Có gì sai với mã?
Khi tôi nhận xét thư thứ ba di chuyển thẻ ra, cuộc gọi thứ hai được thực hiện và lệnh đầu tiên không được thực hiện. Nếu tôi nhận xét cuộc gọi thứ hai và thứ ba, thì cuộc gọi đầu tiên sẽ thực hiện. Nhưng tôi muốn tất cả ba hình ảnh động xuất hiện trên thẻ.
Nhờ đó là hữu ích – Stoner