cwRichardKim / RKSwipeCards

The basics of a swipeable card interface inspired by Tinder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect behaviour in ios7 with constraints

Nebla opened this issue · comments

In ios 7, when the view is using autolayout with constaints, it only rotates and scales when doing pan, it seems that

self.center = CGPointMake(self.originalPoint.x + xFromCenter, self.originalPoint.y + yFromCenter);

isn't working properly in this case (in ios8 it works as expected). What I did to solve this is instead of changing the center property I changed the constraints values (I have four constraints in the view, one for each side), I couldn't figure out another solution. It would be something like this:

CGPoint translation = [gestureRecognizer translationInView:self.superview];

    case UIGestureRecognizerStateBegan:{
        self.originalPoint = self.center;

        originalTop = self.topSpace.constant;
        originalBottom = self.bottomSpace.constant;
        originalTrailling = self.trailingSpace.constant;
        originalLeading = self.leadingSpace.constant;

        break;
    };
    case UIGestureRecognizerStateChanged:{
        ... Stuff ...
        [self updatePositionWithDelta:translation];
  • (void) updatePositionWithDelta:(CGPoint)delta {
    self.topSpace.constant = originalTop + delta.y;
    self.bottomSpace.constant = originalBottom - delta.y;

    self.leadingSpace.constant = originalLeading + delta.x;
    self.trailingSpace.constant = originalTrailling - delta.x;

    [self updateConstraintsIfNeeded];
    }

Hope it helps.

Hey thanks for this. I might contact you later for more details when I look into this


(Choong-Won Richard Kim)

On Tue, Nov 18, 2014 at 1:29 PM, Nebla notifications@github.com wrote:

In ios 7, when the view is using autolayout with constaints, it only rotates and scales when doing pan, it seems that
self.center = CGPointMake(self.originalPoint.x + xFromCenter, self.originalPoint.y + yFromCenter);
isn't working properly in this case (in ios8 it works as expected). What I did to solve this is instead of changing the center property I changed the constraints values (I have four constraints in the view, one for each side), I couldn't figure out another solution. It would be something like this:
CGPoint translation = [gestureRecognizer translationInView:self.superview];
case UIGestureRecognizerStateBegan:{
self.originalPoint = self.center;

        originalTop = self.topSpace.constant;
        originalBottom = self.bottomSpace.constant;
        originalTrailling = self.trailingSpace.constant;
        originalLeading = self.leadingSpace.constant;

        break;
    };
    case UIGestureRecognizerStateChanged:{
        ... Stuff ...
        [self updatePositionWithDelta:translation];
  • (void) updatePositionWithDelta:(CGPoint)delta {
    self.topSpace.constant = originalTop + delta.y;
    self.bottomSpace.constant = originalBottom - delta.y;
    self.leadingSpace.constant = originalLeading + delta.x;
    self.trailingSpace.constant = originalTrailling - delta.x;

    [self updateConstraintsIfNeeded];
    }

    Hope it helps.

    Reply to this email directly or view it on GitHub:
    #6

hey @Nebla and @cwRichardKim I am having the same issue on iOS 7. So I got it working like @Nebla said but I had to take out the rotation and scale transform.. it was behaving very weird and jumping and scaling weird. any ideas?

Hey sorry for the late response. Are you still having this issue? I just tried to replicate it with iOS 7 and it's working fine for me. Are you using a device or a simulator?

I was using a simulator. I ended up deciding that I didnt need the rotation. I still like the look of swiping without rotation. I may dig into it one day and try and figure it out.