objective c - Swift app migration issue -



objective c - Swift app migration issue -

i'm rewriting app swift , worked fine far. tried translate uicollectionviewflowlayout subclass , encountered problems. i'm unable understand how translate layoutattributesforelementsinrect method of class... many errors. problem class it's single 1 i've not written. downloaded class net don't understand logic behind it. can help me? here finish class, need layoutattributesforelementsinrect method since i've translated sec (layoutattributesforitematindexpath) one. , oh, yes! layout left-aligns every cell within corresponding collection view! in advice!

#import "iyalignleftlayout.h" const nsinteger kmaxcellspacing = 30; @implementation iyalignleftlayout - (nsarray *)layoutattributesforelementsinrect:(cgrect)rect { nsarray* attributestoreturn = [super layoutattributesforelementsinrect:rect]; (uicollectionviewlayoutattributes* attributes in attributestoreturn) { if (nil == attributes.representedelementkind) { nsindexpath* indexpath = attributes.indexpath; attributes.frame = [self layoutattributesforitematindexpath:indexpath].frame; } } homecoming attributestoreturn; } - (uicollectionviewlayoutattributes *)layoutattributesforitematindexpath:(nsindexpath *)indexpath { uicollectionviewlayoutattributes* currentitemattributes = [super layoutattributesforitematindexpath:indexpath]; uiedgeinsets sectioninset = uiedgeinsetsmake(50, 20, 50, 20); if (indexpath.item == 0) { // first item of section cgrect frame = currentitemattributes.frame; frame.origin.x = sectioninset.left; // first item of section should left aligned currentitemattributes.frame = frame; homecoming currentitemattributes; } nsindexpath* previousindexpath = [nsindexpath indexpathforitem:indexpath.item-1 insection:indexpath.section]; cgrect previousframe = [self layoutattributesforitematindexpath:previousindexpath].frame; cgfloat previousframerightpoint = previousframe.origin.x + previousframe.size.width + kmaxcellspacing; cgrect currentframe = currentitemattributes.frame; cgrect strecthedcurrentframe = cgrectmake(0, currentframe.origin.y, self.collectionview.frame.size.width, currentframe.size.height); if (!cgrectintersectsrect(previousframe, strecthedcurrentframe)) { // if current item first item on line // approach here take current frame, left align border of view // stretch width of collection view, if intersects previous frame means // on same line, otherwise on it's own new line cgrect frame = currentitemattributes.frame; frame.origin.x = sectioninset.left; // first item on line should left aligned currentitemattributes.frame = frame; homecoming currentitemattributes; } cgrect frame = currentitemattributes.frame; frame.origin.x = previousframerightpoint; currentitemattributes.frame = frame; homecoming currentitemattributes; } @end

try code.

override func layoutattributesforelementsinrect(rect: cgrect) -> anyobject[]! { var attributestoreturn:uicollectionviewlayoutattributes[] = super.layoutattributesforelementsinrect(rect) uicollectionviewlayoutattributes[] attributes in attributestoreturn { if allow elemedkind = attributes.representedelementkind { var indexpath: nsindexpath = attributes.indexpath; attributes.frame = self.layoutattributesforitematindexpath(indexpath).frame } } homecoming attributestoreturn; }

objective-c uicollectionview swift uicollectionviewlayout

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -