के लिए टिंडर-जैसे स्वाइप एनीमेशन जैसे मैंने टिंडर की तरह स्वाइपिंग (http://guti.in/articles/creating-tinder-like-animations/) जोड़ने के बारे में इस बहुत ही उपयोगी ट्यूटोरियल का पालन किया है; हालांकि, मुझे एक समस्या है- जब तस्वीर दूर हो जाती है, तो मैं इसे किसी अन्य तस्वीर से बदलना चाहता हूं। मैं यह कैसे/कहां करूं?आईओएस
आईओएस
उत्तर
मैंने उस ट्यूटोरियल के आधार पर एक सरल और अधिक व्यापक परियोजना बनाई। विशेष रूप से, आप छवियों की एक सरणी का उपयोग कर सकते हैं और छवि के सूचकांक के आधार पर प्रत्येक कार्ड को एक छवि असाइन कर सकते हैं। क्या छवियां गतिशील या स्थैतिक होंगी?
इस बिंदु पर मदद कर सकता है नहीं, लेकिन यहाँ यह वैसे भी है: https://github.com/cwRichardKim/TinderSimpleSwipeCards
इस उत्तर कोड बनाता/cwRichardKim से जवाब दें (आप cwRichardKim धन्यवाद!)। मुझे गाइड नहीं मिला कि प्रत्येक कार्ड में छवियों को कैसे जोड़ा जाए। नीचे मेरी दृष्टिकोण चिपकाने (इस examlple में, छवि यूआरएल कठिन कोडित, लेकिन असली अनुप्रयोग में बादल से छवि url मिल सकता है):
DraggableView.h में:
@property (nonatomic,strong)UIImageView* photoImageView; //%%% a placeholder for member photo to place on card
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];
DraggableViewBackground.h में
:
@property(retain,nonatomic)NSArray* exampleCardUrls;
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;
}
जाँच इस बाहर, beingDragged (_ gestureRecognizer: UIPanGestureRecognizer) समारोह तेजी से 4
https://github.com/nickypatson/TinderSwipeView
में लिखा {
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
}
}
जाने panGestureRecognizer = UIPanGestureRecognizer (लक्ष्य: स्वयं, कार्रवाई : # चयनकर्ता (self.beingDragged)) addGestureRecognizer (panGestureRecognizer)
आशा है कि यह काम करेगा। मुझे पता है
धन्यवाद
- 1. सेटिंग्स.बंडल आईओएस आईओएस 8
- 2. आईओएस लॉगआउट/आईओएस
- 3. आईओएस
- 4. आईओएस
- 5. आईओएस
- 6. आईओएस
- 7. आईओएस
- 8. आईओएस
- 9. आईओएस
- 10. आईओएस
- 11. आईओएस
- 12. आईओएस
- 13. आईओएस
- 14. आईओएस
- 15. आईओएस
- 16. आईओएस
- 17. आईओएस
- 18. आईओएस
- 19. आईओएस
- 20. आईओएस
- 21. आईओएस
- 22. आईओएस
- 23. आईओएस
- 24. आईओएस
- 25. आईओएस
- 26. आईओएस
- 27. आईओएस
- 28. आईओएस
- 29. आईओएस
- 30. आईओएस
पहले एक के नीचे एक और खींचने योग्य दृश्य जोड़ने के लिए किया जाएगा करने के लिए सबसे आसान काम करते हैं। तो आप बस उनके बीच वैकल्पिक। (पहले को खींचते समय, दूसरा तब तक अपने स्थान पर बैठता है जब तक कि पहले ड्रैग नहीं किया जाता है और इसके विपरीत)। तो 2 समान विचार और आप बस वैकल्पिक जो आप खींच रहे हैं और कौन सा छुपा हुआ है। – Dima
https://github.com/modocache/MDCSwipeToChoose यह आपको कुछ समय बचा सकता है। – Tim
इसे आज़माएं https://github.com/nickypatson/TinderSwipeView – nickypatson