Skip to content

Commit a523d1d

Browse files
committed
Merge branch 'develop'
There is no better way to iron out issues by releasing it. :P Conflicts: LXReorderableCollectionViewFlowLayout.podspec
2 parents 42c2fc0 + e66c96d commit a523d1d

File tree

12 files changed

+478
-466
lines changed

12 files changed

+478
-466
lines changed

LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard.xcodeproj/project.pbxproj

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
AB0E97EA161B4C3C005498A0 /* LXCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LXCollectionViewController.m; sourceTree = "<group>"; };
4444
AB0E97EC161B525D005498A0 /* PlayingCard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlayingCard.h; sourceTree = "<group>"; };
4545
AB0E97ED161B525D005498A0 /* PlayingCard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayingCard.m; sourceTree = "<group>"; };
46-
AB0E97F1161B52D4005498A0 /* LXReorderableCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LXReorderableCollectionViewFlowLayout.h; sourceTree = "<group>"; };
47-
AB0E97F2161B52D4005498A0 /* LXReorderableCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LXReorderableCollectionViewFlowLayout.m; sourceTree = "<group>"; };
46+
AB0E97F1161B52D4005498A0 /* LXReorderableCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LXReorderableCollectionViewFlowLayout.h; path = ../LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h; sourceTree = "<group>"; };
47+
AB0E97F2161B52D4005498A0 /* LXReorderableCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LXReorderableCollectionViewFlowLayout.m; path = ../LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m; sourceTree = "<group>"; };
4848
AB0E97F4161B561F005498A0 /* PlayingCardCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlayingCardCell.h; sourceTree = "<group>"; };
4949
AB0E97F5161B561F005498A0 /* PlayingCardCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayingCardCell.m; sourceTree = "<group>"; };
5050
AB0E97F7161B5DC6005498A0 /* Content */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Content; path = ../Content; sourceTree = "<group>"; };
@@ -67,9 +67,9 @@
6767
AB0E97B7161B4BEC005498A0 = {
6868
isa = PBXGroup;
6969
children = (
70-
AB0E97F7161B5DC6005498A0 /* Content */,
71-
AB0E97EF161B52C1005498A0 /* Vendors */,
7270
AB0E97CC161B4BEC005498A0 /* LXRCVFL Example using Storyboard */,
71+
AB0E97EF161B52C1005498A0 /* Library */,
72+
AB0E97F7161B5DC6005498A0 /* Content */,
7373
AB0E97C5161B4BEC005498A0 /* Frameworks */,
7474
AB0E97C3161B4BEC005498A0 /* Products */,
7575
);
@@ -96,16 +96,16 @@
9696
AB0E97CC161B4BEC005498A0 /* LXRCVFL Example using Storyboard */ = {
9797
isa = PBXGroup;
9898
children = (
99+
AB0E97DE161B4BEC005498A0 /* MainStoryboard.storyboard */,
99100
AB0E97D5161B4BEC005498A0 /* AppDelegate.h */,
100101
AB0E97D6161B4BEC005498A0 /* AppDelegate.m */,
101-
AB0E97DE161B4BEC005498A0 /* MainStoryboard.storyboard */,
102-
AB0E97CD161B4BEC005498A0 /* Supporting Files */,
103102
AB0E97E9161B4C3C005498A0 /* LXCollectionViewController.h */,
104103
AB0E97EA161B4C3C005498A0 /* LXCollectionViewController.m */,
105104
AB0E97EC161B525D005498A0 /* PlayingCard.h */,
106105
AB0E97ED161B525D005498A0 /* PlayingCard.m */,
107106
AB0E97F4161B561F005498A0 /* PlayingCardCell.h */,
108107
AB0E97F5161B561F005498A0 /* PlayingCardCell.m */,
108+
AB0E97CD161B4BEC005498A0 /* Supporting Files */,
109109
);
110110
path = "LXRCVFL Example using Storyboard";
111111
sourceTree = "<group>";
@@ -124,22 +124,13 @@
124124
name = "Supporting Files";
125125
sourceTree = "<group>";
126126
};
127-
AB0E97EF161B52C1005498A0 /* Vendors */ = {
128-
isa = PBXGroup;
129-
children = (
130-
AB0E97F0161B52D4005498A0 /* LXReorderableCollectionViewFlowLayout */,
131-
);
132-
name = Vendors;
133-
sourceTree = "<group>";
134-
};
135-
AB0E97F0161B52D4005498A0 /* LXReorderableCollectionViewFlowLayout */ = {
127+
AB0E97EF161B52C1005498A0 /* Library */ = {
136128
isa = PBXGroup;
137129
children = (
138130
AB0E97F1161B52D4005498A0 /* LXReorderableCollectionViewFlowLayout.h */,
139131
AB0E97F2161B52D4005498A0 /* LXReorderableCollectionViewFlowLayout.m */,
140132
);
141-
name = LXReorderableCollectionViewFlowLayout;
142-
path = ../LXReorderableCollectionViewFlowLayout;
133+
name = Library;
143134
sourceTree = "<group>";
144135
};
145136
/* End PBXGroup section */

LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <UIKit/UIKit.h>
1010
#import "LXReorderableCollectionViewFlowLayout.h"
1111

12-
@interface LXCollectionViewController : UICollectionViewController<LXReorderableCollectionViewDelegateFlowLayout>
12+
@interface LXCollectionViewController : UICollectionViewController <UICollectionViewDataSource, LXReorderableCollectionViewDatasource>
1313

1414
@property (strong, nonatomic) NSMutableArray *deck;
1515

LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.m

Lines changed: 87 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,110 +10,132 @@
1010
#import "PlayingCard.h"
1111
#import "PlayingCardCell.h"
1212

13-
@interface LXCollectionViewController ()
13+
// LX_LIMITED_MOVEMENT:
14+
// 0 = Any card can move anywhere
15+
// 1 = Only Spade/Club can move within same rank
1416

15-
@end
17+
#define LX_LIMITED_MOVEMENT 0
1618

1719
@implementation LXCollectionViewController
1820

19-
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
20-
{
21-
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
22-
if (self) {
23-
// Custom initialization
24-
}
25-
return self;
26-
}
27-
28-
- (void)awakeFromNib {
29-
[super awakeFromNib];
21+
- (void)viewDidLoad {
22+
[super viewDidLoad];
3023

3124
self.deck = [self constructsDeck];
3225
}
3326

3427
- (NSMutableArray *)constructsDeck {
35-
NSMutableArray *theDeck = [NSMutableArray arrayWithCapacity:52];
36-
for (NSInteger theRank = 1; theRank <= 13; theRank++) {
28+
NSMutableArray *newDeck = [NSMutableArray arrayWithCapacity:52];
29+
30+
for (NSInteger rank = 1; rank <= 13; rank++) {
3731
// Spade
3832
{
39-
PlayingCard *thePlayingCard = [[PlayingCard alloc] init];
40-
thePlayingCard.suit = PlayingCardSuitSpade;
41-
thePlayingCard.rank = theRank;
42-
[theDeck addObject:thePlayingCard];
33+
PlayingCard *playingCard = [[PlayingCard alloc] init];
34+
playingCard.suit = PlayingCardSuitSpade;
35+
playingCard.rank = rank;
36+
[newDeck addObject:playingCard];
4337
}
4438

4539
// Heart
4640
{
47-
PlayingCard *thePlayingCard = [[PlayingCard alloc] init];
48-
thePlayingCard.suit = PlayingCardSuitHeart;
49-
thePlayingCard.rank = theRank;
50-
[theDeck addObject:thePlayingCard];
41+
PlayingCard *playingCard = [[PlayingCard alloc] init];
42+
playingCard.suit = PlayingCardSuitHeart;
43+
playingCard.rank = rank;
44+
[newDeck addObject:playingCard];
5145
}
5246

5347
// Club
5448
{
55-
PlayingCard *thePlayingCard = [[PlayingCard alloc] init];
56-
thePlayingCard.suit = PlayingCardSuitClub;
57-
thePlayingCard.rank = theRank;
58-
[theDeck addObject:thePlayingCard];
49+
PlayingCard *playingCard = [[PlayingCard alloc] init];
50+
playingCard.suit = PlayingCardSuitClub;
51+
playingCard.rank = rank;
52+
[newDeck addObject:playingCard];
5953
}
6054

6155
// Diamond
6256
{
63-
PlayingCard *thePlayingCard = [[PlayingCard alloc] init];
64-
thePlayingCard.suit = PlayingCardSuitDiamond;
65-
thePlayingCard.rank = theRank;
66-
[theDeck addObject:thePlayingCard];
57+
PlayingCard *playingCard = [[PlayingCard alloc] init];
58+
playingCard.suit = PlayingCardSuitDiamond;
59+
playingCard.rank = rank;
60+
[newDeck addObject:playingCard];
6761
}
6862
}
69-
return theDeck;
63+
64+
return newDeck;
7065
}
7166

72-
- (void)viewDidLoad {
73-
[super viewDidLoad];
74-
// Do any additional setup after loading the view.
67+
#pragma mark - UICollectionViewDataSource methods
68+
69+
- (NSInteger)collectionView:(UICollectionView *)theCollectionView numberOfItemsInSection:(NSInteger)theSectionIndex {
70+
return self.deck.count;
7571
}
7672

77-
- (void)didReceiveMemoryWarning {
78-
[super didReceiveMemoryWarning];
79-
// Dispose of any resources that can be recreated.
73+
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
74+
PlayingCard *playingCard = [self.deck objectAtIndex:indexPath.item];
75+
PlayingCardCell *playingCardCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlayingCardCell" forIndexPath:indexPath];
76+
playingCardCell.playingCard = playingCard;
77+
78+
return playingCardCell;
8079
}
8180

82-
#pragma mark - UICollectionViewDataSource methods
81+
#pragma mark - LXReorderableCollectionViewDataSource methods
8382

84-
- (NSInteger)collectionView:(UICollectionView *)theCollectionView numberOfItemsInSection:(NSInteger)theSectionIndex {
85-
switch (theSectionIndex) {
86-
case 0: {
87-
return [[self valueForKeyPath:@"deck.@count"] integerValue];
88-
} break;
89-
default: {
90-
return 0;
91-
} break;
83+
- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath {
84+
PlayingCard *playingCard = [self.deck objectAtIndex:fromIndexPath.item];
85+
86+
[self.deck removeObjectAtIndex:fromIndexPath.item];
87+
[self.deck insertObject:playingCard atIndex:toIndexPath.item];
88+
}
89+
90+
- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath {
91+
#if LX_LIMITED_MOVEMENT == 1
92+
PlayingCard *playingCard = [deck objectAtIndex:indexPath.item];
93+
94+
switch (playingCard.suit) {
95+
case PlayingCardSuitSpade:
96+
case PlayingCardSuitClub:
97+
return YES;
98+
default:
99+
return NO;
92100
}
101+
#else
102+
return YES;
103+
#endif
93104
}
94105

95-
- (UICollectionViewCell *)collectionView:(UICollectionView *)theCollectionView cellForItemAtIndexPath:(NSIndexPath *)theIndexPath {
96-
NSInteger theSectionIndex = theIndexPath.section;
97-
NSInteger theItemIndex = theIndexPath.item;
98-
switch (theSectionIndex) {
99-
case 0: {
100-
PlayingCard *thePlayingCard = [self.deck objectAtIndex:theItemIndex];
101-
PlayingCardCell *thePlayingCardCell = [theCollectionView dequeueReusableCellWithReuseIdentifier:@"PlayingCardCell" forIndexPath:theIndexPath];
102-
thePlayingCardCell.playingCard = thePlayingCard;
103-
return thePlayingCardCell;
104-
} break;
105-
default: {
106-
return nil;
107-
} break;
106+
- (BOOL)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath canMoveToIndexPath:(NSIndexPath *)toIndexPath {
107+
#if LX_LIMITED_MOVEMENT == 1
108+
PlayingCard *fromPlayingCard = [deck objectAtIndex:fromIndexPath.item];
109+
PlayingCard *toPlayingCard = [deck objectAtIndex:toIndexPath.item];
110+
111+
switch (toPlayingCard.suit) {
112+
case PlayingCardSuitSpade:
113+
case PlayingCardSuitClub:
114+
return fromPlayingCard.rank == toPlayingCard.rank;
115+
default:
116+
return NO;
108117
}
118+
#else
119+
return YES;
120+
#endif
109121
}
110122

111-
#pragma mark - LXReorderableCollectionViewDelegateFlowLayout methods
123+
#pragma mark - LXReorderableCollectionViewDelegate methods
124+
125+
- (void)collectionView:(UICollectionView *)collectionView willBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath {
126+
NSLog(@"will begin drag");
127+
}
128+
129+
- (void)collectionView:(UICollectionView *)collectionView didBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath {
130+
NSLog(@"did begin drag");
131+
}
132+
133+
- (void)collectionView:(UICollectionView *)collectionView willEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath {
134+
NSLog(@"will end drag");
135+
}
112136

113-
- (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout itemAtIndexPath:(NSIndexPath *)theFromIndexPath willMoveToIndexPath:(NSIndexPath *)theToIndexPath {
114-
id theFromItem = [self.deck objectAtIndex:theFromIndexPath.item];
115-
[self.deck removeObjectAtIndex:theFromIndexPath.item];
116-
[self.deck insertObject:theFromItem atIndex:theToIndexPath.item];
137+
- (void)collectionView:(UICollectionView *)collectionView didEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath {
138+
NSLog(@"did end drag");
117139
}
118140

119141
@end

LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/PlayingCard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ typedef NS_ENUM(NSInteger, PlayingCardSuit) {
1919

2020
@property (assign, nonatomic) PlayingCardSuit suit;
2121
@property (assign, nonatomic) NSInteger rank;
22-
@property (copy, nonatomic, readonly) NSString *imageName;
22+
@property (readonly, nonatomic) NSString *imageName;
2323

2424
@end

LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/PlayingCard.m

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
#import "PlayingCard.h"
1010

1111
@implementation PlayingCard
12+
@synthesize suit;
13+
@synthesize rank;
1214

13-
- (NSString *)imageName {
15+
- (NSString *)imageName
16+
{
1417
switch (self.suit) {
15-
case PlayingCardSuitSpade: {
16-
return [NSString stringWithFormat:@"Content/Images/cards_png/s%d.png", self.rank];
17-
} break;
18-
case PlayingCardSuitHeart: {
19-
return [NSString stringWithFormat:@"Content/Images/cards_png/h%d.png", self.rank];
20-
} break;
21-
case PlayingCardSuitClub: {
22-
return [NSString stringWithFormat:@"Content/Images/cards_png/c%d.png", self.rank];
23-
} break;
24-
case PlayingCardSuitDiamond: {
25-
return [NSString stringWithFormat:@"Content/Images/cards_png/d%d.png", self.rank];
26-
} break;
18+
case PlayingCardSuitSpade:
19+
return [NSString stringWithFormat:@"Content/Images/cards_png/s%d.png", rank];
20+
case PlayingCardSuitHeart:
21+
return [NSString stringWithFormat:@"Content/Images/cards_png/h%d.png", rank];
22+
case PlayingCardSuitClub:
23+
return [NSString stringWithFormat:@"Content/Images/cards_png/c%d.png", rank];
24+
case PlayingCardSuitDiamond:
25+
return [NSString stringWithFormat:@"Content/Images/cards_png/d%d.png", rank];
2726
}
2827
}
2928

LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/PlayingCardCell.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
@interface PlayingCardCell : UICollectionViewCell
1414

15-
@property (weak, nonatomic) PlayingCard *playingCard;
16-
17-
@property (weak, nonatomic) IBOutlet UIImageView *playingCardImageView;
18-
15+
@property (strong, nonatomic) PlayingCard *playingCard;
16+
@property (strong, nonatomic) IBOutlet UIImageView *playingCardImageView;
1917

2018
@end

LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/PlayingCardCell.m

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,18 @@
1010
#import "PlayingCard.h"
1111

1212
@implementation PlayingCardCell
13+
@synthesize playingCard;
1314

14-
- (id)initWithFrame:(CGRect)frame
15+
- (void)setPlayingCard:(PlayingCard *)thePlayingCard
1516
{
16-
self = [super initWithFrame:frame];
17-
if (self) {
18-
// Initialization code
19-
}
20-
return self;
17+
playingCard = thePlayingCard;
18+
self.playingCardImageView.image = [UIImage imageNamed:playingCard.imageName];
2119
}
2220

23-
- (void)setPlayingCard:(PlayingCard *)thePlayingCard {
24-
_playingCard = thePlayingCard;
25-
26-
self.playingCardImageView.image = [UIImage imageNamed:self.playingCard.imageName];
27-
}
28-
29-
- (void)setHighlighted:(BOOL)theHighlighted {
30-
[super setHighlighted:theHighlighted];
31-
32-
self.playingCardImageView.alpha = theHighlighted ? 0.75f : 1.0f;
21+
- (void)setHighlighted:(BOOL)highlighted
22+
{
23+
[super setHighlighted:highlighted];
24+
self.playingCardImageView.alpha = highlighted ? 0.75f : 1.0f;
3325
}
3426

3527
@end

LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/en.lproj/MainStoryboard.storyboard

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2843" systemVersion="11E53" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="wfC-9f-vtC">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="3084" systemVersion="12C3006" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="wfC-9f-vtC">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1929"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="2083"/>
55
</dependencies>
66
<scenes>
77
<!--Collection View Controller-->
@@ -42,7 +42,7 @@
4242
</cells>
4343
<connections>
4444
<outlet property="dataSource" destination="wfC-9f-vtC" id="Sdc-G6-mfj"/>
45-
<outlet property="delegate" destination="wfC-9f-vtC" id="ZgU-Og-pdM"/>
45+
<outlet property="delegate" destination="wfC-9f-vtC" id="E63-Wu-Ype"/>
4646
</connections>
4747
</collectionView>
4848
</collectionViewController>

LXReorderableCollectionViewFlowLayout.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'LXReorderableCollectionViewFlowLayout'
3-
s.version = '0.0.2'
3+
s.version = '0.1.0.beta1'
44
s.summary = 'Extends UICollectionViewFlowLayout to support reordering of cells. Similar to long press and pan on books in iBook.'
55
s.homepage = 'https://github.com/lxcid/LXReorderableCollectionViewFlowLayout'
66
s.license = {
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
1010
s.author = 'Stan Chang Khin Boon'
1111
s.source = {
1212
:git => 'https://github.com/lxcid/LXReorderableCollectionViewFlowLayout.git',
13-
:tag => '0.0.2'
13+
:tag => '0.1.0.beta1'
1414
}
1515
s.platform = :ios, '4.3'
1616
s.source_files = 'LXReorderableCollectionViewFlowLayout/'

0 commit comments

Comments
 (0)