zhxnlai/ZLSwipeableView

AutoLayout / XIB

cemkozinoglu opened this issue · 27 comments

Hey awesome piece of code! Problem... When you load a card from XIB.. and move it around stuff within the card does not stay within the bounds.. hard to explain but let me send a screen show.

Are you using autolayout?

It would but I think I found another problem. I read another autolayout/transform suggestion which was;

Wrap everything in the view inside a new host/proxy container view.. And have the container view to set constraints.. What turned out doing that so is.. When i start dragging the Card the frame of the card gets bigger.. Thus the center changes and everything inside the card moved off the bounds.. It wasnt visible before.

I can send a screenshot so you can see what I mean.

Sent from my iPhone

On Dec 2, 2014, at 8:08 PM, Zhixuan Lai notifications@github.com wrote:

Would this post solve your problem?

http://stackoverflow.com/questions/19917420/autolayout-violates-translation-rotation-animation


Reply to this email directly or view it on GitHub.

Yes please.

Ignore the "Invite friends" button please.. that is on a higer index on the main-view not on the card-view.

So as you can see, when I have a structure like:

ViewController
|--------ZLSwipeableView
|------------------------- CardView (UIView)
|-------------- Proxy UIView (which constraints to cardView 0,0,0,0)
|-------------- Rest of the buttons/images etc...

Instead of;

ViewController
|--------ZLSwipeableView
|------------------------- CardView (UIView)
|-------------- Rest of the buttons/images etc...

I can observe that when I move the card around, card starts getting bigger. This could be Bounds vs Frame issue when you are doing your magic?

My guess is that the frame gets bigger after rotation and the view constraints update subviews based on the rotated frame, causing unwanted behaviors. Sorry, I don't have a solution yet but I will keep an eye on it.

zlswipeableviewissue

http://stackoverflow.com/questions/5361369/uiview-frame-bounds-and-center

Are you using Bounds or Frame doing the calculations? I think it might be to do with Frame vs Bound issue. check the thread out.

I am using bounds inside ZLSwipeableView. The problem might be that Autolayout uses frame instead of bounds.

Solved it.. here is the trick after adding the proxy view I mentioned above:

  • (void)swipeableView:(ZLSwipeableView *)swipeableView didStartSwipingView:(UIView *)view atLocation:(CGPoint)location {
    UIView *card = view.subviews[0];
    card.translatesAutoresizingMaskIntoConstraints = YES;

    NSLog(@"did start swiping at location: x %f, y %f", location.x, location.y);
    }

So pretty much disabling autolayout when view starts moving.

Nice, I'm glad that you solved the problem!

On Wednesday, December 3, 2014, Cem Kozinoglu notifications@github.com
wrote:

Solved it.. here is the trick after adding the proxy view I mentioned

above:

(void)swipeableView:(ZLSwipeableView *)swipeableView
didStartSwipingView:(UIView *)view atLocation:(CGPoint)location {
UIView *card = view.subviews[0];
card.translatesAutoresizingMaskIntoConstraints = YES;

NSLog(@"did start swiping at location: x %f, y %f", location.x,
location.y);
}



Reply to this email directly or view it on GitHub
#9 (comment)
.

Great advice! thanks for this, it was driving me crazy!
I implemented a contentView, and didn't need to set translatesAutoresizingMaskIntoConstraints to YES in the delegate or elsewhere. Initializing it with the parent view's bounds was enough for me.

Thanks again! Great lib.

@cemkozinoglu : Can you show me the code how you load the view from xib. I try to do the same thing but have problem while dragging, the image view is not bounded inside the card view (see screenshot)

screen shot 2015-01-02 at 11 33 07

Here are my contraints for my cardview.xib
screen shot 2015-01-02 at 11 34 41

@peacemoon I just updated the demo app. It now includes an example that loads views from xib.

@zhxnlai great, thank you

there are some constrain conflicts, any ideas ?

screen shot 2015-01-19 at 00 07 40

@yingmu52 Thanks for reporting this issue! I just fixed it so please try the latest version of the demo app.

screen shot 2015-01-21 at 15 14 21

thanks for updating the library.. unfortunately, I still get some warnings.

@yingmu52 are you using iOS 8? I double checked and did not get any warning

screen shot 2015-01-23 at 12 25 30
screen shot 2015-01-23 at 12 25 42
screen shot 2015-01-23 at 12 26 56

I am running 7.1.2 on my device. .

@yingmu52 That's weird, I tested it on both iOS 7 and iOS8 simulator and it worked fine

https://www.dropbox.com/sh/6r5leuws1p59lyj/AAATZbxFUSXAhABic3HqTdVoa?dl=0

I have put my custom view under this link, it will be great if you could test it for me. thank you :)

I have an issue where the swipeable view's frame is changed by auto-layout. but the card views have been pinned at the size before the swipeableview frame changed. Anyone know what I need to do?

there are some problems while I use this with autolayout in iOS7