Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions WKPagesCollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
58C2EC3E1A2F223100583CDE /* WKCloseButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 58C2EC3D1A2F223100583CDE /* WKCloseButton.m */; };
68A1CF27184CD0DB00346DF8 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 68A1CF26184CD0DB00346DF8 /* README.md */; };
68BDCE7C18432CCA00DB81A2 /* WKPagesCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 68BDCE7718432CCA00DB81A2 /* WKPagesCollectionView.m */; };
68BDCE7D18432CCA00DB81A2 /* WKPagesCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 68BDCE7918432CCA00DB81A2 /* WKPagesCollectionViewCell.m */; };
Expand All @@ -24,6 +25,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
58C2EC3C1A2F223100583CDE /* WKCloseButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKCloseButton.h; sourceTree = "<group>"; };
58C2EC3D1A2F223100583CDE /* WKCloseButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WKCloseButton.m; sourceTree = "<group>"; };
68A1CF26184CD0DB00346DF8 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = SOURCE_ROOT; };
68BDCE7518432CCA00DB81A2 /* WK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WK.h; sourceTree = "<group>"; };
68BDCE7618432CCA00DB81A2 /* WKPagesCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPagesCollectionView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -75,6 +78,8 @@
68BDCE7918432CCA00DB81A2 /* WKPagesCollectionViewCell.m */,
68BDCE7A18432CCA00DB81A2 /* WKPagesCollectionViewFlowLayout.h */,
68BDCE7B18432CCA00DB81A2 /* WKPagesCollectionViewFlowLayout.m */,
58C2EC3C1A2F223100583CDE /* WKCloseButton.h */,
58C2EC3D1A2F223100583CDE /* WKCloseButton.m */,
);
path = WKPagesCollectionView;
sourceTree = "<group>";
Expand Down Expand Up @@ -205,6 +210,7 @@
68D7C1E918347A08006B418C /* ViewController.m in Sources */,
68D7C1E318347A08006B418C /* AppDelegate.m in Sources */,
68BDCE7C18432CCA00DB81A2 /* WKPagesCollectionView.m in Sources */,
58C2EC3E1A2F223100583CDE /* WKCloseButton.m in Sources */,
68D7C1DF18347A08006B418C /* main.m in Sources */,
68BDCE7E18432CCA00DB81A2 /* WKPagesCollectionViewFlowLayout.m in Sources */,
68BDCE7D18432CCA00DB81A2 /* WKPagesCollectionViewCell.m in Sources */,
Expand Down
13 changes: 13 additions & 0 deletions WKPagesScrollView/WKPagesCollectionView/WKCloseButton.h
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
45 changes: 45 additions & 0 deletions WKPagesScrollView/WKPagesCollectionView/WKCloseButton.m
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];
}

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 the backgroundColor isn't?

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <UIKit/UIKit.h>
#import "WKCloseButton.h"
typedef enum WKPagesCollectionViewCellShowingState:NSUInteger{
WKPagesCollectionViewCellShowingStateNormal=0,
WKPagesCollectionViewCellShowingStateHightlight=1,
Expand All @@ -17,6 +18,7 @@ typedef enum WKPagesCollectionViewCellShowingState:NSUInteger{
WKPagesCollectionViewCellShowingState _showingState;
UITapGestureRecognizer* _tapGesture;
UIScrollView* _scrollView;
WKCloseButton* _closeButton;
// UIImageView* _maskImageView;
}
///Position the normal state
Expand Down
52 changes: 40 additions & 12 deletions WKPagesScrollView/WKPagesCollectionView/WKPagesCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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:
Expand All @@ -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;

Choose a reason for hiding this comment

The 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{

Expand All @@ -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];
}
}
}
Expand Down