zhxnlai / ZLSwipeableView

A simple view for building card like interface inspired by Tinder and Potluck.
MIT License
2.82k stars 330 forks source link

Can we make a delegate like : willSwipeLeft or willSwipeRight #3

Open trungnguyen1791 opened 9 years ago

trungnguyen1791 commented 9 years ago

I wanna make a swipeable view like tinder. So when ever use swipe to left or right, the correspoding button will highlight too.

May be we need a delegate like willSwipeLeft ?

zhxnlai commented 9 years ago

Do you mean a delegate for making text overlay?

trungnguyen1791 commented 9 years ago

Yep, do you have any ideas? For example, if user swiping to the left corner, a delegate will call "swiping to left, show smthing..."

zhxnlai commented 9 years ago

I just added this delegate for obtaining the offset of user's finger translation. Right now you can use the translation parameter to set the alpha of the text overlay. If translation.x is smaller than self.relativeDisplacementThreshold*self.bounds.size.width, the top view will swipe left, and vice versa.

- (void)swipeableView: (ZLSwipeableView *)swipeableView swipingView:(UIView *)view atLocation:(CGPoint)location  translation:(CGPoint)translation {
    NSLog(@"swiping at location: x %f, y %f, translation: x %f, y %f", location.x, location.y, translation.x, translation.y);
}
trungnguyen1791 commented 9 years ago

Thanks so much for this. I have one more question. Can we keep the view's data sources in an array or dictionary? Like the UITableView or UICollectionView. Now we didn't, so if my view has a button, then i try to tap on that button, it will send a message to deallocated view. And of of course it make my app crash

zhxnlai commented 9 years ago

Currently, ZLSwipeableView adds all the views provided by the data source to its view hierarchy as its subviews (subviews are held by strong pointers).

After a view is swiped, ZLSwipeableView simply remove it from the view hierarchy. At this point, if the swiped view is not held by any other strong pointers, it will be garbage collected (like in the demo app).

If you want to use the swiped view afterwards, you should keep a strong reference to it (for instance, by storing the views provided by the data source in an array, which seems like what you are suggesting).

trungnguyen1791 commented 9 years ago

Hmm, i don't want to swipe view afterwards. Just try to place a button on that. But always crash when try to tap on button.

Let me check again. Thanks for your information

zhxnlai commented 9 years ago

Could you show me the code?

trungnguyen1791 commented 9 years ago

The only difference in my code is that i've use a custom view controller with xib instead of CardView (like in the sample project).

And i try to create my view like that : ProfileView *view = [ProfileView customView];

---in ProfileView

I think this's the source of my problem :D

zhxnlai commented 9 years ago

where is the button you mentioned?

trungnguyen1791 commented 9 years ago

In the ProfileView.xib.

zhxnlai commented 9 years ago

shouldn't this

ProfileView customView = [[[NSBundle mainBundle] loadNibNamed:@"ProfileView" owner:nil options:nil] lastObject];

be this?

ProfileView *customView = [[[NSBundle mainBundle] loadNibNamed:@"ProfileView" owner:nil options:nil] lastObject];
trungnguyen1791 commented 9 years ago

Oh, just a mistake when i copy from Xcode to here. Already "ProfileView *customView"

mashun commented 8 years ago

The new version of the sdk I find that you have to put some property before deleted, for example: self.relativeDisplacementThreshold, swipeableViewsCenter..I want to achieve and tinder, slide left or right slide when the card appears like it or not tag