Re: -replaceSubview transition animation that is applied to both old and new subviews
Re: -replaceSubview transition animation that is applied to both old and new subviews
- Subject: Re: -replaceSubview transition animation that is applied to both old and new subviews
- From: Nick <email@hidden>
- Date: Sun, 01 Nov 2015 00:40:04 +0200
Answering my own question - I ended up using NSPageController.
2015-10-29 8:55 GMT+02:00 Nick <email@hidden>:
> Hi
> I am trying to do a nice sliding effect (that looks to the user as
> Calendar scrolling), but for pages. So basically I have several pages that
> I want to present to the user one by one, that he can flip with a trackpad
> gesture.
>
> I am using a kCATransitionFromLeft animation, when the pages are being
> flipped backwards:
>
> -(IBAction)prevPage:(id)sender {
> if(self.currentPageIndex <= 0)
> return; //no previous subview
>
> [self.pageDisplayView
> removeConstraints:self.pageDisplayView.constraints];
>
> CATransition *trans = [CATransition animation];
> trans.type = kCATransitionMoveIn;
> trans.subtype = kCATransitionFromLeft;
> self.pageDisplayView.animations = @{@"subviews": trans};
>
> [[self.pageDisplayView animator]
> replaceSubview:self.pages[self.currentPageIndex]
> with:self.pages[self.currentPageIndex-1]];
> self.currentPageIndex--;
>
> NSDictionary *subView = @{@"page": self.pages[self.currentPageIndex]};
> NSArray *hConstraints = [NSArray array];
> hConstraints = [hConstraints
> arrayByAddingObjectsFromArray:[NSLayoutConstraint
> constraintsWithVisualFormat:@"H:|[page]|" options:0 metrics:nil
> views:subView]];
> NSArray *vConstraints = [NSArray array];
> vConstraints = [hConstraints
> arrayByAddingObjectsFromArray:[NSLayoutConstraint
> constraintsWithVisualFormat:@"V:|[page]|" options:0 metrics:nil
> views:subView]];
> [self.pagedisplayView addConstraints:hConstraints];
> [self.pageDisplayView addConstraints:vConstraints];
> }
>
> But the problem is that the previous (old) subview, that is being replaced
> by the new one, does not animate - only the new one does. So it doesn't
> look like scrolling, more like the new page goes over the old page.
> I would like to have the old subview move from right to left as it
> disappears (as in slide out) as well.
> How could I achieve this?
>
> And just as a subquestion, how is continuous swipe gesture tracking
> usually implemented? Basically I was hoping to have the user to be able to
> swipe the pages left (go to the next page) and right (go to the prev page),
> but in such a way that while his fingers are still on the trackpad, the
> page doesn't move away completely but stays "in a transition". Something
> like pages in Safari, when you go back and forward with the swipe gesture
> but do not take the fingers off the trackpad. I was wondering how did Apple
> do this?
>
> Thank you for reading this far and possible suggestions!
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden