Có cách nào sao chép hoạt ảnh phát sáng nút siri không? Nó trông hoàn toàn tuyệt đẹp, nhưng tôi không có ý tưởng tại thời điểm làm thế nào để bắt đầu ... là có pngs định dạng trực tuyến được luân chuyển? hoặc là nó được thực hiện với CoreAnimation?Tạo lại Nút Siri Glow Animation
Trả lời
Tôi tin rằng hoạt hình Siri được tạo bằng CAEmitterLayer và CAEmitterCell và sau đó hoạt ảnh với hoạt ảnh lõi, nhưng tôi có thể hoàn toàn sai. Dưới đây là một số mã bắt chước hiệu ứng:
// create emitter layer
self.emitterLayer = [CAEmitterLayer layer];
self.emitterLayer.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
self.emitterLayer.emitterMode = kCAEmitterLayerOutline;
self.emitterLayer.emitterShape = kCAEmitterLayerLine;
self.emitterLayer.renderMode = kCAEmitterLayerAdditive;
[self.emitterLayer setEmitterSize:CGSizeMake(4, 4)];
// create the ball emitter cell
CAEmitterCell *ball = [CAEmitterCell emitterCell];
ball.color = [[UIColor colorWithRed:111.0/255.0 green:80.0/255.0 blue:241.0/255.0 alpha:0.10] CGColor];
ball.contents = (id)[[UIImage imageNamed:@"ball.png"] CGImage]; // ball.png is simply an image of white circle
[ball setName:@"ball"];
self.emitterLayer.emitterCells = [NSArray arrayWithObject:ball];
[self.view.layer addSublayer:self.emitterLayer];
float factor = 1.5; // you should play around with this value
[self.emitterLayer setValue:[NSNumber numberWithInt:(factor * 500)] forKeyPath:@"emitterCells.ball.birthRate"];
[self.emitterLayer setValue:[NSNumber numberWithFloat:factor * 0.25] forKeyPath:@"emitterCells.ball.lifetime"];
[self.emitterLayer setValue:[NSNumber numberWithFloat:(factor * 0.15)] forKeyPath:@"emitterCells.ball.lifetimeRange"];
// animation code
CAKeyframeAnimation* circularAnimation = [CAKeyframeAnimation animationWithKeyPath:@"emitterPosition"];
CGMutablePathRef path = CGPathCreateMutable();
CGRect pathRect = CGRectMake(0, 0, 200, 200); // define circle bounds with rectangle
CGPathAddEllipseInRect(path, NULL, pathRect);
circularAnimation.path = path;
CGPathRelease(path);
circularAnimation.duration = 2;
circularAnimation.repeatDuration = 0;
circularAnimation.repeatCount = 3;
circularAnimation.calculationMode = kCAAnimationPaced;
[self.emitterLayer addAnimation:circularAnimation forKey:@"circularAnimation"];
Lớp CAEmitterCell và CAEmitterLayer có nhiều thuộc tính nên hãy xem tài liệu để biết thêm.
Tôi khuyên bạn nên làm điều đó với PNG được hiển thị từng cái một sao cho kết quả hoạt ảnh mượt mà. Đó là cách dễ dàng hơn so với lập trình một hình ảnh động được mã hóa. Nút đã được tạo lại bởi Arron Hunt: Siri Button Photoshop File
Btw. Một phim hoạt hình sprite là rất dễ dàng để thực hiện:
- (void)viewDidLoad {
[super viewDidLoad];
NSArray * imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"],
[UIImage imageNamed:@"10.png"],
[UIImage imageNamed:@"11.png"],
[UIImage imageNamed:@"12.png"],
nil];
UIImageView * ryuJump = [[UIImageView alloc] initWithFrame:
CGRectMake(100, 125, 150, 130)];
ryuJump.animationImages = imageArray;
ryuJump.animationDuration = 1.1;
ryuJump.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:ryuJump];
[ryuJump startAnimating];
}
Nguồn: http://www.icodeblog.com/2009/07/24/iphone-programming-tutorial-animating-a-game-sprite/
Bạn đã có một điểm ... Vì vậy, việc triển khai đủ PNG cho hoạt ảnh xoay sẽ là một cách. Tôi luôn nghĩ rằng những thứ như vậy phải được thực hiện với CoreAnimation vì nó dễ sửa đổi hơn. Liên kết là tuyệt vời! Tôi sẽ xem xét điều đó! – konturgestaltung
Hãy xem câu trả lời đã chỉnh sửa của tôi để biết mã mẫu có hoạt ảnh sprite. Chúc may mắn – Sbhklr
@Lightforce, Ai cũng có thể thiết lập hình ảnh PNG cho tệp PSD này, tôi không có bất kỳ kiến thức Photoshop nào để trích xuất hình ảnh. Có thể tải lên một số hình ảnh để mọi người dễ sử dụng. . – user1227928
UIImageView có một tính chất gọi animationImages mà bạn có thể sử dụng để xác định một danh sách các hình ảnh mà nó sẽ chơi theo thứ tự, giống như một GIF động . Đó có lẽ là cách dễ nhất để làm điều đó nếu bạn muốn kiểm soát chính xác hiệu ứng.
Điều gì đó tương tự cũng có thể được thực hiện với CoreAnimation bằng cách sử dụng một hình ảnh đơn và làm hoạt hình thuộc tính view.transform của nó bằng cách sử dụng CGAffineTransformMakeRotation (góc).
Đó cũng là suy nghĩ đầu tiên của tôi ... tạo ra một hình ảnh phát sáng với một gradient và alpha 0 tại một và theo hình tròn và xoay điều đó ... nhưng tôi không chắc liệu nó có tạo ra hiệu ứng phát sáng hay không. .. bởi vì nó vẫn sẽ trông tĩnh? – konturgestaltung
Bạn cũng có thể muốn thay đổi độ alpha theo thời gian, vì vậy hãy làm mờ alpha vào và ra khi nó quay để làm cho nó xuất hiện xung quanh một chút. –
tốt đẹp ..... nên làm điều đó ..... Tôi cho nó một thử !! – konturgestaltung
- 1. Lặp lại android animation
- 2. Tạo Chọn Hộp Glow Blue trong Twitter Bootstrap
- 3. Ngôn ngữ lập trình Siri
- 4. Silverlight 2: Hiệu ứng Glow Text?
- 5. Tạo lớp phủ mờ animatable với lớp Animation Lõi
- 6. Pulsing Animation
- 7. Hoạt ảnh lõi Chaining Animation Animation
- 8. Boolean Animation khóa thuộc tính
- 9. Outer Glow như bóng đổ HLSL
- 10. UISearchBar Animation
- 11. Matplotlib Animation
- 12. WPF Choppy Animation
- 13. jQuery backgroundColor animation
- 14. Android Fragment Animation onResume
- 15. Brush to Brush Animation
- 16. Android Animation Flicker
- 17. Có cách nào để giải quyết thiếu API cho Siri?
- 18. Custom Animation trong Raphaël.js
- 19. JQuery slideDown animation lag
- 20. Android ViewFlipper Animation
- 21. Android Simple TextView Animation
- 22. Android Translate Animation
- 23. WPF Fade Animation
- 24. Java Swing tải Animation
- 25. Java Swing Dice Rolling Animation
- 26. Tắt CSS3 Animation Với jQuery?
- 27. chờ animation với HTML5 Canvas
- 28. UIImageView Animation không giữ khung cuối cùng
- 29. Hoạt ảnh lặp lại, có thể đảo ngược bằng cách sử dụng Core Animation
- 30. Thay đổi cornerRadius sử dụng Core Animation
self.fireEmitter thiếu ngữ cảnh ở đây – Pascalius
Tôi đã quên chỉnh sửa các dòng đó khi sao chép mã. Nó đáng lẽ phải là self.emitterLayer. Tôi đã sửa nó. – jlajlar
Bạn quên đề cập rằng "ball.png" phải có kích thước khoảng 5x5 pixel ... – Idan