Tôi đã làm theo hướng dẫn rất hữu ích này về cách thêm swiping giống như tinder (http://guti.in/articles/creating-tinder-like-animations/); tuy nhiên, tôi có một vấn đề - khi bức tranh biến mất, tôi muốn thay thế nó bằng một bức ảnh khác. Làm thế nào/nơi nào tôi làm điều đó?Hình động vuốt giống như hình nền cho iOS
Trả lời
Tôi đã xây dựng một dự án đơn giản và toàn diện hơn dựa trên hướng dẫn đó. Đặc biệt, bạn có thể sử dụng một loạt các hình ảnh và gán cho mỗi thẻ một hình ảnh dựa trên chỉ mục của hình ảnh. Các hình ảnh có động hoặc tĩnh không?
không thể giúp vào thời điểm này, nhưng ở đây nó là anyway: https://github.com/cwRichardKim/TinderSimpleSwipeCards
câu trả lời này được xây dựng trên mã/trả lời từ cwRichardKim (cảm ơn bạn cwRichardKim!). tôi không tìm thấy hướng dẫn cách thêm hình ảnh vào từng thẻ. dán cách tiếp cận của tôi dưới đây (trong examlple này, url hình ảnh cứng mã hóa, nhưng trong ứng dụng thực tế có thể có được url hình ảnh từ điện toán đám mây):
trong DraggableView.h:
@property (nonatomic,strong)UIImageView* photoImageView; //%%% a placeholder for member photo to place on card
trong DraggableView.m:
...
@synthesize photoImageView;
...
// - (id)initWithFrame:(CGRect)frame ...
// add photo to card
//You need to specify the frame of the view
UIView *photoView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.frame.size.width,self.frame.size.width)];
photoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"place_holder_image.png"]];
// UIImageView *imageView = [[UIImageView alloc] initWithImage:photo];
//specify the frame of the imageView in the superview , here it will fill the superview
photoImageView.frame = photoView.bounds;
// add the imageview to the superview
[photoView addSubview:photoImageView];
//add the view to the main view
[self addSubview:photoView];
trong DraggableViewBackground.h:
@property(retain,nonatomic)NSArray* exampleCardUrls;
trong DraggableViewBackground.m:
...
@synthesize exampleCardUrls;
...
exampleCardUrls = [[NSArray alloc]initWithObjects:@"http://images.clipartpanda.com/clipart-people-nTBX8zkgc.jpeg",@"http://epilepsyu.com/wp-content/uploads/2014/01/happy-people.jpg",@"http://alivecampus.com/wp-content/uploads/2014/09/people-02.jpg",@"https://www.google.com/images/srpr/logo11w.png",@"http://modalpoint.com/wp-content/uploads/2014/11/people-blue-stick-people-hi.png", nil];
...
// ... -(DraggableView *)createDraggableViewWithDataAtIndex:(NSInteger)index ...
// retrieve image for cell in background
NSURL *url = [NSURL URLWithString:exampleCardUrls[index]];
[self loadImage:url withIndex:index];
...
#pragma mark - cloud, load image
- (void)loadImage:(NSURL *)imageURL withIndex:(NSInteger)index
{
// create array of objects to pass to next method
NSMutableArray* params = [[NSMutableArray alloc]init];
[params addObject:imageURL];
NSNumber *indexNumber = [NSNumber numberWithInt:index];
[params addObject:indexNumber];
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(requestRemoteImage:)
object:params];
[queue addOperation:operation];
}
- (void)requestRemoteImage:(NSMutableArray*)params
{
// get data from params
NSURL* imageURL = params[0];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
UIImage *image = [[UIImage alloc] initWithData:imageData];
params[0] = image;
[self performSelectorOnMainThread:@selector(placeImageInUI:) withObject:params waitUntilDone:YES];
}
- (void)placeImageInUI:(NSArray*)params
{
// get data from params
UIImage* image = params[0];
NSNumber* indexNumber = params[1];
NSInteger index = [indexNumber integerValue];
DraggableView* myDraggableView = allCards[index];
myDraggableView.photoImageView.image = image;
allCards[index] = myDraggableView;
}
việc kiểm tra này ra, viết bằng nhanh chóng 4
https://github.com/nickypatson/TinderSwipeView
func beingDragged (_ gestureRecognizer: UIPanGestureRecognizer) {
xFromCenter = gestureRecognizer.translation(in: self).x
yFromCenter = gestureRecognizer.translation(in: self).y
switch gestureRecognizer.state {
//%%% just started swiping
case .began:
originalPoint = self.center;
break;
//%%% in the middle of a swipe
case .changed:
let rotationStrength = min(xFromCenter/ROTATION_STRENGTH, ROTATION_MAX)
let rotationAngel = .pi/8 * rotationStrength
let scale = max(1 - fabs(rotationStrength)/SCALE_STRENGTH, SCALE_MAX)
center = CGPoint(x: originalPoint.x + xFromCenter, y: originalPoint.y + yFromCenter)
let transforms = CGAffineTransform(rotationAngle: rotationAngel)
let scaleTransform: CGAffineTransform = transforms.scaledBy(x: scale, y: scale)
self.transform = scaleTransform
updateOverlay(xFromCenter)
break;
case .ended:
afterSwipeAction()
break;
case .possible:break
case .cancelled:break
case .failed:break
}
}
hãy panGestureRecognizer = UIPanGestureRecognizer (mục tiêu: tự, hành động : #selector (self.beingDragged)) addGestureRecognizer (panGestureRecognizer)
Hy vọng điều này sẽ hiệu quả. Hãy cho tôi biết
nhờ
- 1. UICollectionView giống như Màn hình chính iOS
- 2. Chọn nền cho Hình nền động
- 3. Hình nền iOS 6
- 4. CSS in giống như màn hình
- 5. Android: vuốt màn hình để mở một hoạt động khác?
- 6. Vuốt giữa các hình ảnh được lọc cho android
- 7. Hình nền toàn màn hình iOS cho tất cả các kích thước màn hình
- 8. iOS 8 - Gradient nền cho tệp màn hình khởi chạy
- 9. Đặt nền ứng dụng giống với hình nền màn hình chính
- 10. Mô hình khung giống như Django
- 11. img hoạt động như một hình nền img?
- 12. Hình nền cho wrap_content
- 13. iOS: springWithDamping giống như hoạt ảnh cho hoạt ảnh KeyFrame
- 14. Hình động màu nền nhanh chóng
- 15. Hình nền canvas wpf động
- 16. cách tạo màn hình vuốt động trong android?
- 17. Hình nền hoạt động Android
- 18. Cách làm cho màu sắc trên một màn hình trông giống như một màn hình khác
- 19. Hình ảnh có thể xem có thể bị xóa trong các thẻ <img> giống như hình nền
- 20. Quét hình ảnh WPF để thay đổi hình ảnh như trong iOS
- 21. Hình ảnh băm cho hình ảnh rất giống nhau
- 22. Hình nền cuộn cho UITableView?
- 23. Hình ảnh hoạt hình nền
- 24. Âm thanh nền iOS dừng khi màn hình bị khóa
- 25. Vòng tròn xung hoạt hình IOS giống như quả bóng màu xanh trên bản đồ
- 26. Đặt hình nền cho màu phông chữ?
- 27. hàng đợi tin nhắn cho iOS/iPad - giống như MSMQ?
- 28. kích thước hình nền cho thiết bị di động
- 29. Hình nền động - "Đặt hình nền" - Cần sự kiện để xóa bộ nhớ
- 30. Hoạt động Android - nền drawable hoạt hình
Điều dễ nhất để làm sẽ có thêm một cái nhìn kéo bên dưới cái đầu tiên. Sau đó, bạn chỉ cần luân phiên giữa chúng. (Trong khi kéo người đầu tiên, người thứ hai ngồi tại chỗ của nó cho đến khi người đầu tiên bị kéo đi và ngược lại). Vì vậy, 2 quan điểm giống hệt nhau và bạn chỉ cần thay thế cái mà bạn đang kéo và cái nào bị ẩn. – Dima
https://github.com/modocache/MDCSwipeToChoose Điều này có thể giúp bạn tiết kiệm thời gian. – Tim
dùng thử https://github.com/nickypatson/TinderSwipeView – nickypatson