Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a delegate to signal animation completion #6

Open
ghost opened this issue Sep 30, 2013 · 15 comments
Open

Add a delegate to signal animation completion #6

ghost opened this issue Sep 30, 2013 · 15 comments

Comments

@ghost
Copy link

ghost commented Sep 30, 2013

Hi Colin,

I just finished working on the chapter about Custom transitions, so I was very surprised (and happy) to see that this library in CocoaControls was in fact yours !
Thanks for this awesome library :-)

I would like to implement a "fold" transition with a TabBarController with 2 tabs. But I would like each tab to have a distinct color when selected.
Unfortunately, the horizontal swipe does not go through:

  • (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

so I don't have a chance to set self.view.tintColor to the right color.

Is there a way to set the toVC tab tintColor when using an horizontal swipe ?

Thanks
Frederic

@ghost ghost closed this as completed Sep 30, 2013
@ghost ghost reopened this Sep 30, 2013
@ColinEberhardt
Copy link
Owner

Hi FredddyF,

Glad you liked the book - and yes ... I have been busy!

Interactive transitions with tab bar controllers have cause me a few headaches as well. I have also found that the delegate methods are not 'fired' when used with interaction controllers. For this reason, in my example code I use key-value-observing on the properties of the tab bar controller.

After some more testing, I think the technique I a using is still intermittent. I have made a few minor tweaks, and pushed to this branch here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/tree/tab-bar-interactions

This should be ore reliable.

To set your tint colour, look at the code here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/blob/tab-bar-interactions/TabBarDemo/TabBarDemo/TabBarViewController.m#L44

Use KVO on the selectedViewController property. This should change for both interactive and non-interactive transitions.

Hope the helps.

@ghost
Copy link
Author

ghost commented Oct 1, 2013

Thanks a lot for your quick answer, I'll try this out right away !
I must say I'm a big fan of your tutorials, I learned a lot with your tutorial about a to-do list like Clear, and this one about Custom transitions gave me new ideas for my apps !

Thanks !!

Cordialement,
Frédéric

Le 1 oct. 2013 à 07:37, ColinEberhardt [email protected] a écrit :

Hi FredddyF,

Glad you liked the book - and yes ... I have been busy!

Interactive transitions with tab bar controllers have cause me a few headaches as well. I have also found that the delegate methods are not 'fired' when used with interaction controllers. For this reason, in my example code I use key-value-observing on the properties of the tab bar controller.

After some more testing, I think the technique I a using is still intermittent. I have made a few minor tweaks, and pushed to this branch here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/tree/tab-bar-interactions

This should be ore reliable.

To set your tint colour, look at the code here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/blob/tab-bar-interactions/TabBarDemo/TabBarDemo/TabBarViewController.m#L44

Use KVO on the selectedViewController property. This should change for both interactive and non-interactive transitions.

Hope the helps.


Reply to this email directly or view it on GitHub.

@ghost
Copy link
Author

ghost commented Oct 1, 2013

Colin,

Just to give you an update : I tried to set the tab tintColor in the KVO on selectedViewController property.
Unfortunately, what happens is that the selectedViewController property changes as soon as the gesture is initiated ... which changes the icon color of the "from tab" instead of the "to tab" :

Tapped on the first tab : Beer is orange : good :

Tapped on the second tab : Wine is red : good

Swiped to the right : Wine is orange : not so good :-)

The thing is : I wouldn't want to mess with the animationController or InteractiveController classes, they are supposed to be independent from the TabBarController ...

Also, the following line in CEHorizontalSwipeInteractionController.m has a problem :
(method handleGesture:)

} else {
if (currentIndex + 1 > 0) {
self.interactionInProgress = YES;
_viewController.tabBarController.selectedViewController = _viewController.tabBarController.viewControllers[currentIndex - 1];
}
}

If the current VC is the first one in the viewControllers array, the index is 0 and this will cause a crash.
The correct condition would be if (currentIndex > 0)

Cordialement,
Frédéric

Le 1 oct. 2013 à 07:37, ColinEberhardt [email protected] a écrit :

Hi FredddyF,

Glad you liked the book - and yes ... I have been busy!

Interactive transitions with tab bar controllers have cause me a few headaches as well. I have also found that the delegate methods are not 'fired' when used with interaction controllers. For this reason, in my example code I use key-value-observing on the properties of the tab bar controller.

After some more testing, I think the technique I a using is still intermittent. I have made a few minor tweaks, and pushed to this branch here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/tree/tab-bar-interactions

This should be ore reliable.

To set your tint colour, look at the code here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/blob/tab-bar-interactions/TabBarDemo/TabBarDemo/TabBarViewController.m#L44

Use KVO on the selectedViewController property. This should change for both interactive and non-interactive transitions.

Hope the helps.


Reply to this email directly or view it on GitHub.

@ColinEberhardt
Copy link
Owner

Thanks for pointing out that bug (I'll make sure not to merge that branch!)

I agree that the animation / interaction controllers shouldn't be meddled with.

Do you think it would help to add a delegate to the interaction controller that signals when the transition has completed?

@ghost
Copy link
Author

ghost commented Oct 1, 2013

Hi Colin

That sounds like a great idea !
I was thinking about a public BOOL property to indicate that the transition was complete, but delegation seems a better method.

I plan to spend some time on this subject on Thursday, looks like a lot of fun !

Thanks

Cordialement,
Frédéric

Le 1 oct. 2013 à 22:14, ColinEberhardt [email protected] a écrit :

Thanks for pointing out that bug (I'll make sure not to merge that branch!)

I agree that the animation / interaction controllers shouldn't be meddled with.

Do you think it would help to add a delegate to the interaction controller that signals when the transition has completed?


Reply to this email directly or view it on GitHub.

@ghost
Copy link
Author

ghost commented Oct 3, 2013

Hi Colin,

The delegate worked fine !

I created a CEInteractionControllerDelegate protocol (yes, it begins with CE, as a tribute :-)

@protocol CEInteractionControllerDelegate

@optional

  • (void)didFinishInteraction;

@EnD

I then set this property in the CEBaseInteractionController.h
@Property (nonatomic, weak) id interactionDelegate;

In the CEBaseInteractionController.m, I added this :

  • (void)finishInteractiveTransition
    {
    [super finishInteractiveTransition];

    SEL finishMethod = @selector(didFinishInteraction);

    if ([self.interactionDelegate respondsToSelector:finishMethod]) {
    [self.interactionDelegate didFinishInteraction];
    }

}

Back to the TabBarViewController, I added the following

In initWithCoder:
_interactionController.interactionDelegate = self;

Added this method :
#pragma mark - Interaction controller delegate

  • (void)didFinishInteraction
    {
    [self assignTabColor];
    }

And this one:

  • (void)assignTabColor
    {
    // switch (self.selectedIndex) {
    // case 0:
    // self.view.tintColor = [UIColor orangeColor];
    // self.selectedViewController.title = NSLocalizedString(@"Beer", @"Beer");
    // break;
    //
    // case 1:
    // self.view.tintColor = [UIColor redWineColor];
    // self.selectedViewController.title = NSLocalizedString(@"Wine", @"Wine");
    // break;
    //
    // default:
    // break;
    // }

    if ([self.selectedViewController isKindOfClass:[PBBeerViewController class]]) {
    self.view.tintColor = [UIColor orangeColor];
    self.selectedViewController.title = NSLocalizedString(@"Beer", @"Beer");

    } else if ([self.selectedViewController isKindOfClass:[PBWineViewController class]]) {
    self.view.tintColor = [UIColor redWineColor];
    self.selectedViewController.title = NSLocalizedString(@"Wine", @"Wine");
    }
    }

Now I still have to finish the challenge for chapter 3 in iOS7 by Tutorials ... back to work :-)

Thanks for your help !

Cordialement,
Frédéric

Le 1 oct. 2013 à 22:14, ColinEberhardt [email protected] a écrit :

Thanks for pointing out that bug (I'll make sure not to merge that branch!)

I agree that the animation / interaction controllers shouldn't be meddled with.

Do you think it would help to add a delegate to the interaction controller that signals when the transition has completed?


Reply to this email directly or view it on GitHub.

@ghost ghost closed this as completed Oct 3, 2013
@ColinEberhardt ColinEberhardt reopened this Oct 3, 2013
@ColinEberhardt
Copy link
Owner

Thanks for letting me know that this idea worked for you.

I've re-opened this issue because I think the delegate is something I should add to VCTransitionsLibrary so that everyone can benefit from this approach.

@ghost
Copy link
Author

ghost commented Dec 8, 2013

Hi Colin,

I continued exploring Custom VC transitions, and I came up with 2 new transitions :

  • a "portal opening" one, which looks a bit like a Keynote transition
  • a way to transition from a collectionView cell to a UIViewController, zooming on an item.

The first one looks cool, so I thought I would share it with you, in case you like it ! That's not much, but I feel like I owe you a lot after all you've shared in the tutorials on raywenderlich.com.
I'm not sure it works with an interactionController, though ...

The second one is a bit more tricky : I want to zoom in from a collectionView item, until it takes the main spot in a UIViewController.

1 - click on the duck "card"

2 - transiiton : the card "zooms in"

3 - the full image is presented in a UIViewController

That works OK but in order to keep my classes separated, I need to pass the frame that the little card is supposed to reach (forwards transition), and the frame in the collection view that the full image is supposed to reach ...
Basically, in the "prepareForSegue", I give the animationController the "from-view" frame in the collectionView (and I know that it should then reach the center of the UIViewController's view), and in an unwind segue, I give the animationController the from- and to- frames for the animation.

And the problem is : if I transition from the collectionView to the UIViewController, then rotate my iPad then go back, the reverse transition fails because my transition kept track of the position it had in the collectionView, but the rotation will cause the VC to give a new layout to the collectionView.

If you could just give me a hint or set me on track about how to "predict" what will the frame of a cell be in the new layout of the collectionView, I'll be more than grateful !

Here are my classes :

AlbumViewController is where the collectionView is, ImageviewController is a UIViewcontroller presenting the image "full screen" and the zoomInAnimationController is my animationController.

Thanks !
Frederic

@ColinEberhardt
Copy link
Owner

Hi @FredddyF - I'd love to see your transitions, but they have been stripped out of your comment. Perhaps you could commit them to a fork? Or upload them to a gist?

@ghost
Copy link
Author

ghost commented Dec 9, 2013

Thanks Colin !

Sorry, I didn't know how to contact you otherwise ! I'm still a github newbie :-)

I created a Fork named "portal animation" to VCTransitionsLibrary.

And here is a link to a repo of my own app on Github :
https://github.com/FredddyF/BabyBook-v2--iOS7-
(it's stripped of sound files to take less space, but you can still play the animations)
I detailed the issue I meet in a new "issue" point.

I'd love to hear your comments !

Thanks

Regards,
Frédéric

Le 9 déc. 2013 à 09:53, ColinEberhardt [email protected] a écrit :

Hi @FredddyF - I'd love to see your transitions, but they have been stripped out of your comment. Perhaps you could commit them to a fork? Or upload them to a gist?


Reply to this email directly or view it on GitHub.

@ColinEberhardt
Copy link
Owner

Hi Frédéric, I've just downloaded that app - it looks awesome!

Do you mind if I add your portal animation to this library? (I'll attribute it to you and link to your GitHub page).

Thanks, Colin E.

@ghost
Copy link
Author

ghost commented Dec 10, 2013

Hi Colin,

Sure, I'd be honored !
However, I tried to integrate the portal animation within VCTransitionsLibrary, but it doesn't seem to work well with the interaction controller ... I can't find what's wrong. Maybe I'll check again later ... After I had a fair share of sleep :-)

And if you have an idea about how to determine the position of a collection view cell before it's displayed on screen and after a rotation has occurred, you'd save me a few sleepless nights ;-)

Thanks a lot !

Regards
Frederic

Le 10 déc. 2013 à 07:44, ColinEberhardt [email protected] a écrit :

Hi Frédéric, I've just downloaded that app - it looks awesome!

Do you mind if I add your portal animation to this library? (I'll attribute it to you and link to your GitHub page).

Thanks, Colin E.


Reply to this email directly or view it on GitHub.

@ColinEberhardt
Copy link
Owner

Thanks Freddy, I've added your Portal animation. I had to make a few changes in order for it to reverse properly. You can see them here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/commits/master/AnimationControllers/CEPortalAnimationController.m

Thanks again :-)

@ghost
Copy link
Author

ghost commented Dec 10, 2013

Great, thanks !!

Cordialement,
Frédéric

Le 10 déc. 2013 à 23:31, ColinEberhardt [email protected] a écrit :

Thanks Freddy, I've added your Portal animation. I had to make a few changes in order for it to reverse properly. You can see them here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/commits/master/AnimationControllers/CEPortalAnimationController.m

Thanks again :-)


Reply to this email directly or view it on GitHub.

@ghost
Copy link
Author

ghost commented Dec 13, 2013

Hi Colin

I wanted to let you know that I found a workaround for my animation to set an Image from an Image view controller back to its place in a collectionView in an Album View controller.

The issue was :

  • the original frame in the AlbumVC collectionView was stored in the "prepareForSegue" to ImageVC
  • it was used when going back to the AlbumVC, in an unwind segue.
    I had a problem when rotating the device when showing the ImageViewController because when the unwind segue fires, the collectionView hasn't defined its layout yet ... so the frame I had stored earlier is no longer valid.

What I did is :

  • in the ImageViewController, I detect if the device has rotated. If yes, I set a BOOL property "hasDeviceRotated" (public) to yes
  • in the unwind segue of the AlbumVC, I check this bool property of the ImageVC : if it's no, then my original frame is still valid and I use it ; if it's yes, then my original frame is no longer valid and I just get the image out of the screen.
    Not as beautiful as when the image gets back in the collectionView, right to its former place, but I guess it's honorable, and I don't think too many people will change orientation right at that precise moment ...

A bit difficult to explain, so I just updated my project in GitHub here :
https://github.com/FredddyF/BabyBook-v2--iOS7-

Thanks for your help and your tutorials, they are an endless source of inspiration, hints and useful tricks ;-)

Best regards,
Frédéric

Le 10 déc. 2013 à 23:37, Frédéric ADDA [email protected] a écrit :

Great, thanks !!

Cordialement,
Frédéric

Le 10 déc. 2013 à 23:31, ColinEberhardt [email protected] a écrit :

Thanks Freddy, I've added your Portal animation. I had to make a few changes in order for it to reverse properly. You can see them here:

https://github.com/ColinEberhardt/VCTransitionsLibrary/commits/master/AnimationControllers/CEPortalAnimationController.m

Thanks again :-)


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant