Làm thế nào để bạn xoay UIView
, UIImageView
hoặc CALayer
hoạt hình 360 degress mà không sử dụng OpenGL ES?Làm thế nào để bạn xoay UIView, UIImageView hoặc CALayer hoạt ảnh 360˚?
5
A
Trả lời
3
Có lẽ bạn muốn quay phim an toàn UIImage
xung quanh 360 ° đầy đủ? Theo kinh nghiệm của tôi, cách để hoàn thành một vòng quay vòng tròn đầy đủ là chuỗi nhiều động tác khác nhau:
- (IBAction)rotate:(id)sender
{
[UIView beginAnimations:@"step1" context:NULL]; {
[UIView setAnimationDuration:1.0];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
[imageView.transform = CGAffineTransformMakeRotation(120 * M_PI/180);
} [UIView commitAnimations];
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([animationID isEqualToString:@"step1"]) {
[UIView beginAnimations:@"step2" context:NULL]; {
[UIView setAnimationDuration:1.0];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
imageView.transform = CGAffineTransformMakeRotation(240 * M_PI/180);
} [UIView commitAnimations];
}
else if ([animationID isEqualToString:@"step2"]) {
[UIView beginAnimations:@"step3" context:NULL]; {
[UIView setAnimationDuration:1.0];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
imageView.transform = CGAffineTransformMakeRotation(0);
} [UIView commitAnimations];
}
}
Tôi đã rời khỏi đường cong easeIn/easeOut
(thay vì tuyến tính) tại chỗ, do đó bạn có thể xem các hình ảnh động cá nhân.
28
#import <QuartzCore/QuartzCore.h>
CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = @(0.0);
fullRotation.toValue = @((360.0 * M_PI)/180.0);
fullRotation.duration = 3.5f;
fullRotation.repeatCount = MAXFLOAT;
[view.layer addAnimation:fullRotation forKey:@"rotation-animation"];
Nếu bạn muốn thay đổi các điểm neo để nó quay xung quanh sau đó bạn có thể làm
CGRect frame = view.layer.frame;
self.anchorPoint = CGPointMake(0.5, 0.5); // rotates around center
self.frame = frame;
Các vấn đề liên quan
- 1. Góc tròn UIView hoặc UIImageView
- 2. Hoạt ảnh UIImage hoặc UIImageView?
- 3. CATransform3DRotate xoay 360 độ
- 4. CALayer Shadows biến mất trong một hoạt ảnh UIView
- 5. Làm thế nào để xoay một UIImageView với CATransform3DRotate làm cho một hiệu ứng như mở cửa?
- 6. Làm thế nào để bạn di chuyển một CALayer ngay lập tức (không có hoạt ảnh)
- 7. Xoay hình ảnh trong UIImageView
- 8. UIImageView điền vào UIView
- 9. Xoay ảnh. Danh sách hoạt ảnh hoặc xoay động? (Android)
- 10. iphone xoay UIImageView
- 11. iPhone: CALayer + xoay trong 3D + antialias?
- 12. Làm cách nào để thêm ánh sáng bên ngoài vào UIImage hoặc UIImageView hoặc UIView
- 13. Hoạt ảnh "Wobbly" trên iPhone UiImageView
- 14. Cách dừng hoạt ảnh UIView
- 15. Hoạt ảnh kết thúc cuộc gọi lại cho CALayer?
- 16. Xoay hoạt ảnh android
- 17. làm thế nào để bạn sao chép một CALayer?
- 18. Làm thế nào để tôi xoay một CALayer xung quanh một đường chéo?
- 19. Xoay UIImageView theo chiều kim đồng hồ
- 20. IOS: xoay một UIImageView
- 21. Hoạt ảnh UIView so với CALayers
- 22. Gói/cong vênh một CALayer/UIView (hoặc OpenGL) trong 3D (iPhone)
- 23. Đặt chuyển đổi xoay thành UIView hoặc lớp của nó dường như không hoạt động?
- 24. iOS CAKeyframeChế độ xoay vòngMode trên UIImageView
- 25. Cách thực hiện chống răng cưa trên UIView được xoay (KHÔNG UIImageView)
- 26. Áp dụng Box2D vật lý để UIView vs CALayer
- 27. iPhone Hoạt ảnh UIView Tắt UIButton Subview
- 28. Làm cách nào để tắt hoạt ảnh cho mã lồng nhau trong khối hoạt ảnh UIView?
- 29. Xoay UIView trong Cocoa Touch
- 30. Xoay 360 độ đầy đủ trong WPF 3D
Bạn nhận ra rằng 360˚ xoay sẽ cung cấp cho bạn những hình ảnh chính xác cùng, phải không? – SteamTrout
Tôi thấy buồn khi tôi bắt đầu nghĩ về một giải pháp trước khi tôi nhận ra điều đó. – jtbandes
@Steam Trout: chỉ khi bạn muốn nó tức thời. – JeremyP