iphone - iOS map view in table view cell wrong frame origin -
i need set position of map view in table view cell. set frame in cellforrow method.
some of map views misplaced. when scroll table , scroll down let reappear (to reuse table cell), fixed.
note
the y position wrong x position correct.
i use same way (simply set frame) set pictures position , correct. problem map view instead of how position frame.
the following screenshot shows 3 map views, middle 1 has wrong y position
edit:
the ui part quite complicated. inside cellforrowatindexpath method, dequeue messagecell , call setupwithmessage:(message *)message method , check if message of type location: (a location type message has optional text view , map view)
self.textview.hidden = no; self.mapview.hidden = no; self.textview.text = message.text; [helper setupmapview:self.mapview posx:message.posx posy:message.posy]; cgsize size1 = [uihelper sizewithtext:message.text entity:message]; cgsize size2 = [uihelper sizewithmapentity:message]; cgrect frame = [uihelper adjusttextview:self.textview textviewsize:size1 extraview:self.mapview extraviewsize:size2 entity:message]; + (cgrect)adjusttextview:(uitextview *)textview textviewsize:(cgsize)textviewsize extraview:(uiview *)extraview extraviewsize:(cgsize)extraviewsize entity:(id)entity { if (textview == nil || extraview == nil || cgsizeequaltosize(textviewsize, cgsizezero) || cgsizeequaltosize(extraviewsize, cgsizezero)) { cgsize targetsize; uiview *targetview; if (textview == nil || cgsizeequaltosize(textviewsize, cgsizezero)) { targetview = extraview; targetsize = extraviewsize; } else { targetview = textview; targetsize = textviewsize; } return [self adjustcontentview:targetview size:targetsize entity:entity]; } else { cgrect frame1 = [self adjustcontentview:textview size:textviewsize entity:entity]; cgrect frame2 = [self adjustcontentview:extraview size:extraviewsize entity:entity]; frame2.origin.y += frame1.size.height + offset_between_textview_extraview; extraview.frame = frame2; return cgrectmake(frame1.origin.x, frame1.origin.y, max(frame1.size.width, frame2.size.width), frame1.size.height + frame2.size.height + offset_between_textview_extraview); }
note "extraview" above can refer view below text view, such uiimageview
+ (cgrect)adjustcontentview:(uiview *)contentview size:(cgsize) size entity:(id)entity { float photosideoffset = 60; float topoffset = 30; cgrect frame; frame.origin.y = topoffset; frame.size = size; if ([dbhelper ismyentity:entity]) { frame.origin.x = 320 - size.width - photosideoffset; } else { frame.origin.x = photosideoffset; } contentview.frame = frame; if ([contentview iskindofclass:[uitextview class]]) { [(uitextview *)contentview sizetofit]; } return contentview.frame; }
edit 2: use same uihelper methods photo messages , coordinates correct:
edit 3: value of size1 size2 , frame
the workaround propose isnt "solution" "alternative"
instead of putting mkmapview cell, can create snapshot map view. , can create image cells map cell. suggestion trigger action when user click on image cell , push new "mapviewcontroller" modal.
self.textview.hidden = no; self.thumbnailbutton.hidden = no; self.textview.text = message.text; [helper setupmapsnapshotthumbnailbutton:self.thumbnailbutton withposx:message.posx posy:message.posy size:message_size_map]; cgsize size1 = [uihelper sizewithtext:message.text entity:message]; cgsize size2 = message_size_map; cgrect frame = [uihelper adjusttextview:self.textview textviewsize:size1 extraview:self.thumbnailbutton extraviewsize:size2 entity:message]; [self setupcommonoutletswithcontentframe:frame];
and can create image using
mkmapsnapshotoptions *options = [[mkmapsnapshotoptions alloc] init]; options.scale = [uiscreen mainscreen].scale; options.region = [self private_mapregionwithposx:posx posy:posy]; options.size = size; mkmapsnapshotter *snapshotter = [[mkmapsnapshotter alloc] initwithoptions:options]; [snapshotter startwithcompletionhandler:^(mkmapsnapshot *snapshot, nserror *error) { [thumbnailbutton setbackgroundimage:snapshot.image forstate:uicontrolstatenormal]; }];
btw snapshot code works ios 7. if need ios6 or earlier support, need bit of cg coding
Comments
Post a Comment