-(void) Viewdidload {
[Super Viewdidload];
Additional setup after loading the view, typically from a nib.
Self.title = @ "card rollover effect";
Self.edgesforextendedlayout = Uirectedgenone;
[Self.view AddSubview:self.collectionView];
Nsarray * arr = @[@ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0" @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0", @ "0"];
[Arr enumerateobjectsusingblock:^ (id _nonnull obj, nsuinteger idx, BOOL * _nonnull stop) {
Model *model =[[model alloc] init];
Model.select = [obj boolvalue];
[Self.dataarray Addobject:model];
}];
[Self.collectionview Reloaddata];
}
-(Nsmutablearray *) dataarray{
if (!_dataarray) {
_dataarray = [Nsmutablearray array];
}
return _dataarray;
}
-(Uicollectionview *) collectionview{
if (!_collectionview) {
Uicollectionviewflowlayout * layout = [[Uicollectionviewflowlayout alloc] init];
Define Size
Layout.itemsize = Cgsizemake ((appWidth-40)/2.0, 0.8* (appWidth-40)/2.0);
Set Minimum line spacing
layout.minimumlinespacing = 10;
Set Vertical Spacing
layout.minimuminteritemspacing = 10;
Layout.sectioninset = Uiedgeinsetsmake (15, 15, 15, 15);
Set Vertical Spacing
layout.headerreferencesize = cgsizemake (0, 0);
Set scrolling direction (default vertical scrolling)
Layout.scrolldirection = uicollectionviewscrolldirectionvertical;
_collectionview = [[Uicollectionview alloc] Initwithframe:cgrectmake (0, 0, appwidth, appHeight-64) Collectionviewlayout:layout];
_collectionview.backgroundcolor = [Uicolor Clearcolor];
_collectionview.delegate = self;
_collectionview.datasource = self;
[_collectionview registernib:[uinib Nibwithnibname:nsstringfromclass ([Homecollectionviewcell class]) Bundle:nil] forcellwithreuseidentifier:@ "Homecell"];
}
return _collectionview;
}
-(Nsinteger) Numberofsectionsincollectionview: (Uicollectionview *) collectionview{
return 1;
}
-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (NSInteger) section{
return self.dataArray.count;
}
-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) indexpath{
Homecollectionviewcell * cell = [CollectionView dequeuereusablecellwithreuseidentifier:@ "HomeCell" ForIndexPath: Indexpath];
Model * model = Self.dataarray[indexpath.item];
if (Model.select = = YES) {
Cell.secondView.hidden = YES;
Cell.firstview.hidden = NO;
}else{
Cell.secondView.hidden = NO;
Cell.firstview.hidden = YES;
}
Cell.bt.tag = Indexpath.item;
[Cell.bt addtarget:self Action: @selector (didbtaction:event:) forcontrolevents:uicontroleventtouchupinside];
return cell;
}
-(void) CollectionView: (Uicollectionview *) CollectionView Willdisplaycell: (Uicollectionviewcell *) cell Foritematindexpath: (Nsindexpath *) indexpath{
model* model = Self.dataarray[indexpath.item];
Homecollectionviewcell * Cell1 = (Homecollectionviewcell *) cell;
if (Model.select = = YES) {
Cell1.secondView.hidden = YES;
Cell1.firstview.hidden = NO;
}else{
Cell1.secondView.hidden = NO;
Cell1.firstview.hidden = YES;
}
}
-(void) Didbtaction: (UIButton *) Sender Event: (uievent *) event{
Nsset *touches = [Event Alltouches];
Uitouch *touch = [touches anyobject];
Cgpoint position = [Touch LocationInView:self.collectionView];
Nsindexpath *indexpath = [Self.collectionview indexpathforitematpoint:position];
Nsindexpath *indexpath = [Nsindexpath indexPathForRow:sender.tag insection:0];
Homecollectionviewcell *cell = (homecollectionviewcell*) [Self.collectionview Cellforitematindexpath:indexpath];
In this case, look for a sub-view in the view (this looks, possibly because there are more than two views in the parent view)
Nsinteger fist= [[Cell subviews] Indexofobject:[cell viewwithtag:1000]];
Nsinteger seconde= [[Cell subviews] Indexofobject:[cell viewwithtag:2000]];
model* model = Self.dataarray[indexpath.item];
3, 3D Flip Animation
[UIView animatewithduration:1.0 animations:^{
if (Model.select = = YES)
{
Cell.secondView.hidden = NO;
Cell.firstview.hidden = YES;
Model.select = NO;
[Self.dataarray ReplaceObjectAtIndex:indexPath.item withobject:model];//is currently showing a positive view
[UIView setanimationtransition:uiviewanimationtransitionflipfromright Forview:cell Cache:yes];
}
Else
{
Cell.secondView.hidden = YES;
Cell.firstview.hidden = NO;
Model.select = YES;
[Self.dataarray ReplaceObjectAtIndex:indexPath.item withobject:model];//is currently showing the back view
[UIView setanimationtransition:uiviewanimationtransitionflipfromleft Forview:cell Cache:yes];
}
}];
}
IOS Uicollectionview for card rollover effects