forked from adow/WKPagesCollectionView
-
Notifications
You must be signed in to change notification settings - Fork 0
Add a close button #12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // | ||
| // WKCloseButton.h | ||
| // WKPagesCollectionView | ||
| // | ||
| // Created by Xu Zhao on 3/12/14. | ||
| // Copyright (c) 2014 秦 道平. All rights reserved. | ||
| // | ||
|
|
||
| #import <UIKit/UIKit.h> | ||
|
|
||
| @interface WKCloseButton : UIButton | ||
|
|
||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // | ||
| // WKCloseButton.m | ||
| // WKPagesCollectionView | ||
| // | ||
| // Created by Xu Zhao on 3/12/14. | ||
| // Copyright (c) 2014 秦 道平. All rights reserved. | ||
| // | ||
|
|
||
| #import "WKCloseButton.h" | ||
| #import <QuartzCore/QuartzCore.h> | ||
| @implementation WKCloseButton | ||
|
|
||
|
|
||
| -(id) initWithFrame:(CGRect)frame | ||
| { | ||
| self = [super initWithFrame:frame]; | ||
| if (self){ | ||
| [self drawCloseButton]; | ||
| } | ||
| return self; | ||
|
|
||
| } | ||
| #pragma mark - DrawButton | ||
| -(void) drawCloseButton | ||
| { | ||
| self.backgroundColor = [UIColor clearColor]; | ||
| CGFloat xOffset = self.bounds.size.width / 7; | ||
| CGFloat yOffset = self.bounds.size.width / 7; | ||
| CGFloat width = self.frame.size.width * 0.3; | ||
| CGFloat height = self.frame.size.height * 0.3; | ||
| UIBezierPath *path = [UIBezierPath bezierPath]; | ||
| [path moveToPoint:CGPointMake(xOffset, yOffset)]; | ||
| [path addLineToPoint:CGPointMake(width + xOffset, height + yOffset)]; | ||
| [path moveToPoint:CGPointMake(width + xOffset, yOffset)]; | ||
| [path addLineToPoint:CGPointMake(xOffset, height + yOffset)]; | ||
|
|
||
| CAShapeLayer *shapeLayer = [CAShapeLayer layer]; | ||
| [shapeLayer setPath:[path CGPath]]; | ||
| [shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]]; | ||
| [shapeLayer setLineWidth:1.0f]; | ||
|
|
||
| [[self layer] addSublayer:shapeLayer]; | ||
| } | ||
|
|
||
| @end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,9 @@ | |
|
|
||
| #import "WKPagesCollectionViewCell.h" | ||
| #import "WKPagesCollectionView.h" | ||
| #import "WKCloseButton.h" | ||
| #define CloseButtonWidth 35 | ||
| #define CloseButtonHeight CloseButtonWidth * 1.5 | ||
| @implementation WKPagesCollectionViewCell | ||
| @dynamic showingState; | ||
| - (id)initWithFrame:(CGRect)frame | ||
|
|
@@ -44,6 +47,13 @@ - (id)initWithFrame:(CGRect)frame | |
| _tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onTapGesture:)]; | ||
| [_scrollView addGestureRecognizer:_tapGesture]; | ||
| } | ||
|
|
||
| if (!_closeButton) { | ||
| _closeButton = [[WKCloseButton alloc] initWithFrame:CGRectMake(0, 0, CloseButtonWidth, CloseButtonHeight)]; | ||
| [_closeButton addTarget:self action:@selector(closeButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; | ||
| [_scrollView addSubview:_closeButton]; | ||
| } | ||
|
|
||
| } | ||
| return self; | ||
| } | ||
|
|
@@ -77,6 +87,12 @@ -(IBAction)onTapGesture:(UITapGestureRecognizer*)tapGesture{ | |
| NSLog(@"highlight completed"); | ||
| }]; | ||
| } | ||
|
|
||
| -(void) closeButtonPressed:(id)sender | ||
| { | ||
| [self removeCurrentCell]; | ||
|
|
||
| } | ||
| #pragma mark - Properties | ||
| -(void)setShowingState:(WKPagesCollectionViewCellShowingState)showingState{ | ||
| if (_showingState==showingState) | ||
|
|
@@ -89,6 +105,7 @@ -(void)setShowingState:(WKPagesCollectionViewCellShowingState)showingState{ | |
| case WKPagesCollectionViewCellShowingStateHightlight:{ | ||
| self.normalTransform=self.layer.transform;///The original location of the first record | ||
| _scrollView.scrollEnabled=NO; | ||
| _closeButton.hidden = YES; | ||
| NSIndexPath* indexPath=[self.collectionView indexPathForCell:self]; | ||
| CGFloat moveY=self.collectionView.contentOffset.y-(WKPagesCollectionViewPageSpacing)*indexPath.row +topMargin; | ||
| CATransform3D moveTransform=CATransform3DMakeTranslation(0.0f, moveY, 0.0f); | ||
|
|
@@ -98,20 +115,23 @@ -(void)setShowingState:(WKPagesCollectionViewCellShowingState)showingState{ | |
| case WKPagesCollectionViewCellShowingStateBackToTop:{ | ||
| self.normalTransform=self.layer.transform;///The original location of the first record | ||
| _scrollView.scrollEnabled=NO; | ||
| _closeButton.hidden = NO; | ||
| CATransform3D moveTransform=CATransform3DMakeTranslation(0, -1*pageHeight-topMargin, 0); | ||
| self.layer.transform=CATransform3DConcat(CATransform3DIdentity, moveTransform); | ||
| } | ||
| break; | ||
| case WKPagesCollectionViewCellShowingStateBackToBottom:{ | ||
| self.normalTransform=self.layer.transform;///The original location of the first record | ||
| _scrollView.scrollEnabled=NO; | ||
| _closeButton.hidden = NO; | ||
| CATransform3D moveTransform=CATransform3DMakeTranslation(0, pageHeight+topMargin, 0); | ||
| self.layer.transform=CATransform3DConcat(CATransform3DIdentity, moveTransform); | ||
| } | ||
| break; | ||
| case WKPagesCollectionViewCellShowingStateNormal:{ | ||
| self.layer.transform=self.normalTransform; | ||
| _scrollView.scrollEnabled=YES; | ||
| _closeButton.hidden = NO; | ||
| } | ||
| break; | ||
| default: | ||
|
|
@@ -124,6 +144,25 @@ -(void)setShowingState:(WKPagesCollectionViewCellShowingState)showingState{ | |
| -(WKPagesCollectionViewCellShowingState)showingState{ | ||
| return _showingState; | ||
| } | ||
|
|
||
|
|
||
| -(void) removeCurrentCell | ||
| { | ||
| NSIndexPath* indexPath=[self.collectionView indexPathForCell:self]; | ||
| NSLog(@"delete cell at %ld",(long)indexPath.row); | ||
| //self.alpha=0.0f; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to commit commented logic |
||
| //Delete data | ||
| id<WKPagesCollectionViewDataSource> pagesDataSource=(id<WKPagesCollectionViewDataSource>)self.collectionView.dataSource; | ||
| [pagesDataSource collectionView:(WKPagesCollectionView*)self.collectionView willRemoveCellAtIndexPath:indexPath]; | ||
| //Animation | ||
| [self.collectionView performBatchUpdates:^{ | ||
| [self.collectionView deleteItemsAtIndexPaths:@[indexPath,]]; | ||
| } completion:^(BOOL finished) { | ||
|
|
||
| }]; | ||
|
|
||
| } | ||
|
|
||
| #pragma mark - UIScrollViewDelegate | ||
| -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ | ||
|
|
||
|
|
@@ -135,18 +174,7 @@ -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL) | |
| if (self.showingState==WKPagesCollectionViewCellShowingStateNormal){ | ||
| CGFloat slideDistance = scrollView.frame.size.width / 6; | ||
| if (scrollView.contentOffset.x >= slideDistance){ | ||
| NSIndexPath* indexPath=[self.collectionView indexPathForCell:self]; | ||
| NSLog(@"delete cell at %ld",(long)indexPath.row); | ||
| //self.alpha=0.0f; | ||
| ///Delete data | ||
| id<WKPagesCollectionViewDataSource> pagesDataSource=(id<WKPagesCollectionViewDataSource>)self.collectionView.dataSource; | ||
| [pagesDataSource collectionView:(WKPagesCollectionView*)self.collectionView willRemoveCellAtIndexPath:indexPath]; | ||
| ///Animation | ||
| [self.collectionView performBatchUpdates:^{ | ||
| [self.collectionView deleteItemsAtIndexPaths:@[indexPath,]]; | ||
| } completion:^(BOOL finished) { | ||
|
|
||
| }]; | ||
| [self removeCurrentCell]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come
[self drawCloseButton]is in the if statement, but setting thebackgroundColorisn't?