From a3b41b9065ca9abe843f1f1d45e5ae8d3b556031 Mon Sep 17 00:00:00 2001 From: Raymond Walsh Date: Fri, 22 Apr 2016 11:55:37 -0700 Subject: [PATCH] Update SwipeView & SwipeViewDelegate to allow views to be controlled by View Controllers Added optional delegate callbacks which are called at the right times to allow the SwipeViewDelegate to have the views controlled by UIViewController subclasses --- SwipeView/SwipeView.h | 16 ++++++++++++++++ SwipeView/SwipeView.m | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/SwipeView/SwipeView.h b/SwipeView/SwipeView.h index 2fb12dd..f75dee5 100755 --- a/SwipeView/SwipeView.h +++ b/SwipeView/SwipeView.h @@ -122,6 +122,22 @@ typedef NS_ENUM(NSUInteger, SwipeViewAlignment) - (BOOL)swipeView:(SwipeView *)swipeView shouldSelectItemAtIndex:(NSInteger)index; - (void)swipeView:(SwipeView *)swipeView didSelectItemAtIndex:(NSInteger)index; +//These method gives you the overrides you need to have the subviews controlled by a UIViewController +//Presumably you will call -[willMoveToParentViewController:nil] +- (void)swipeView:(SwipeView *)swipeView willRemoveSubview:(UIView *)view forItemAtIndex:(NSInteger)index; + +//These method gives you the overrides you need to have the subviews controlled by a UIViewController +//Presumably you will call -[removeFromParentViewController] +- (void)swipeView:(SwipeView *)swipeView didRemoveSubview:(UIView *)view forItemAtIndex:(NSInteger)index; + +//These method gives you the overrides you need to have the subviews controlled by a UIViewController +//Presumably you will call -[addChildViewController:] +- (void)swipeView:(SwipeView *)swipeView willAddSubview:(UIView *)view forItemAtIndex:(NSInteger)index; + +//These method gives you the overrides you need to have the subviews controlled by a UIViewController +//Presumably you will call -[didMoveToParentViewController:] +- (void)swipeView:(SwipeView *)swipeView didAddSubview:(UIView *)view forItemAtIndex:(NSInteger)index; + @end diff --git a/SwipeView/SwipeView.m b/SwipeView/SwipeView.m index 04e942b..0fb8ad8 100755 --- a/SwipeView/SwipeView.m +++ b/SwipeView/SwipeView.m @@ -896,7 +896,16 @@ - (UIView *)loadViewAtIndex:(NSInteger)index [self setItemView:view forIndex:index]; [self setFrameForView:view atIndex:index]; view.userInteractionEnabled = YES; + + if (_delegate && [_delegate respondsToSelector:@selector(swipeView:willAddSubview:forItemAtIndex:)]) + { + [self.delegate swipeView:self willAddSubview:oldView forItemAtIndex:index]; + } [_scrollView addSubview:view]; + if (_delegate && [_delegate respondsToSelector:@selector(swipeView:didAddSubview:forItemAtIndex:)]) + { + [self.delegate swipeView:self didAddSubview:oldView forItemAtIndex:index]; + } return view; } @@ -959,7 +968,15 @@ - (void)loadUnloadViews { UIView *view = _itemViews[number]; [self queueItemView:view]; + if (_delegate && [_delegate respondsToSelector:@selector(swipeView:willRemoveSubview:forItemAtIndex:)]) + { + [self.delegate swipeView:self willRemoveSubview:view forItemAtIndex:number.integerValue]; + } [view removeFromSuperview]; + if (_delegate && [_delegate respondsToSelector:@selector(swipeView:didRemoveSubview:forItemAtIndex:)]) + { + [self.delegate swipeView:self didRemoveSubview:view forItemAtIndex:number.integerValue]; + } [_itemViews removeObjectForKey:number]; } }