ios - How do I show selected sticker (image) on preview subview? -
i have been working on chat app can send sticker. have done far when tap on sticker on sticker view, selected sticker sent chat room immediately. asked add stickerpreviewview pops when tap on sticker , selected sticker shown on stickerpreviewview first awaiting user response. if user tap on selected sticker (uibutton sticker image on it), sent chat room. question how can given below related code shows how send sticker chat room.
inputfunctionview
// method called when tap on sticker - (void)selectedsticker:(nsstring *)stickerurlstring { gstickerurlstring = stickerurlstring; // added sanit - pass on stickerurlstring global variable // added sanit - initialize stickerpreviewview _stickerpreviewview = [[uiimageview alloc] initwithframe:cgrectmake(0, +180, framewidth, 120)]; _stickerpreviewview.backgroundcolor = [[uicolor blackcolor] colorwithalphacomponent:0.5f]; _stickerpreviewview.userinteractionenabled = yes; [self.superview addsubview:_stickerpreviewview]; // added sanit - use superview add subview stickerpreviewview; using self add subview not working ? // added sanit - initialize previewcancelbutton self.previewcancelbutton = [uibutton buttonwithtype:uibuttontypecustom]; self.previewcancelbutton.frame = cgrectmake(main_screen_width-30, spaceforitems, 25, 25); [self.previewcancelbutton setbackgroundimage:[uiimage imagenamed:@"btn_previewcancel.png"] forstate:uicontrolstatenormal]; [self.previewcancelbutton setbackgroundimage:[uiimage imagenamed:@"btn_previewcancel.png"] forstate:uicontrolstatehighlighted]; [_stickerpreviewview addsubview: self.previewcancelbutton]; [self.previewcancelbutton addtarget:self action:@selector(cancelstickerpreviewbuttonpressed:) forcontrolevents:uicontroleventtouchupinside]; // added sanit - initialize stickerpreviewbutton self.stickerpreviewbutton = [uibutton buttonwithtype:uibuttontypecustom]; self.stickerpreviewbutton.frame = cgrectmake(main_screen_width/2, spaceforitems, 60, 60); [_stickerpreviewview addsubview: self.stickerpreviewbutton]; [self.stickerpreviewbutton addtarget:self action:@selector(sendstickerpreviewbuttonpressed:) forcontrolevents:uicontroleventtouchupinside]; // added sanit - stickerpreviewbutton fires action // how add selected sticker display on stickerpreviewview? //??? call method show sticker on stickerpreviewview here - how? } // added sanit - method when cancelstickerpreviewbutton pressed - (void)cancelstickerpreviewbuttonpressed:(id)sender { nslog(@"cancel sticker preview"); [self.previewcancelbutton removefromsuperview]; [_stickerpreviewview removefromsuperview]; } // added sanit - method called when stickerpreviewbutton pressed - (void)sendstickerpreviewbuttonpressed: (uibutton *)sender { [self.delegate inputfunctionview:self sendsticker:gstickerurlstring]; // added sanit - send off sticker chatroom [self cancelstickerpreviewbuttonpressed:nil]; } //??? added sanit - method show sticker on stickerpreviewview - how?
chatroomvc
check chatroomvc see how sends sticker chat room - i'm trying replicate way send sticker stickerpreviewview it's not simple , need here.
- (void)inputfunctionview:(inputfunctionview *)funcview sendsticker:(nsstring *)stickerurlstring { nsdictionary *dic = @{@"sticker" : stickerurlstring, @"type" : @(messagetypesticker), @"target" : _targetaccout, @"topic" : _topic, @"isgroupmessage" : @"0"}; if (_chatroomtype == chatroomtypegroup) { dic = @{@"sticker" : stickerurlstring, @"type" : @(messagetypesticker), @"target" : _gid, //_targetaccout @"topic" : _topic, @"isgroupmessage" : @"1"}; } [self dealthefunctiondata:dic]; [self.view endediting:yes]; } - (void)dealthefunctiondata:(nsdictionary *)dic { if ([objectmanager isconnectedtointernet] && [[mqttmanager sharedinstance].client mqttstatus]) { [self.chatmodel addmymessage:dic]; [self.chattableview reloaddata]; [self tableviewscrolltobottom]; } else { if ([dic[@"type"] intvalue] == 0) { ifview.textviewinput.text = dic[@"strcontent"]; } [objectmanager showisconnectedtointernetfailwithduration:1.0 inview:self.view]; }
chatmodelview
- (void)addmymessage:(nsdictionary *)dic { bool istempmessage=false; bool isusingtempmessage=false; /*************** mqtt ***************/ //check message type messagetype messagetype = [dic[@"type"] integervalue]; if ([[nsstring stringwithformat:@"%@", dic[@"isgroupmessage"]] isequaltostring:@"1"]) { _chatroomusertype = yes; } nsstring *messagestring; nsstring *reftempid; //"strcontent" if (messagetype == messagetypetext) { messagestring = dic[@"strcontent"]; //"picture" } else if (messagetype == messagetypepicture) { messagestring = dic[@"picture"]; reftempid=dic[@"reftempid"]; if (reftempid!=nil) { isusingtempmessage=true; nslog(@"reftempid=%@",reftempid); } //"voice" } else if (messagetype == messagetypevoice) { messagestring = dic[@"voice"]; //"sticker" } else if (messagetype == messagetypesticker) { messagestring = dic[@"sticker"]; messagestring = [messagestring stringbyreplacingoccurrencesofstring:kstickerimageurl withstring:@""]; //"video" } else if (messagetype == messagetypevideo) { messagestring = dic[@"video"]; } nsstring *targetstring = dic[@"target"]; nsstring *topicstring = dic[@"topic"]; nsstring *tempid=[nsstring stringwithformat:@"%@",dic[@"tempid"]]; if (![tempid isequaltostring:@"(null)"]) { nslog(@"temp id not empty"); istempmessage=true; } nsstring *messageid = [[user shareduser] generatedoublemessageid]; double timestamp = [[nsdate date] timeintervalsince1970] * 1000; if (!istempmessage) { [self sendmessagetomqttserver:messagestring target:targetstring topic:topicstring messagetype:messagetype messageid:messageid timestamp:timestamp]; } /* layout */ nsmutabledictionary *datadic = [nsmutabledictionary dictionarywithdictionary:dic]; nsstring *urlstr = @"http://img0.bdstatic.com/img/image/shouye/xinshouye/mingxing16.jpg"; [datadic setobject:@(messagefromme) forkey:@"from"]; [datadic setobject:[[nsdate date] description] forkey:@"strtime"]; [datadic setobject:@"hello,sister" forkey:@"strname"]; [datadic setobject:urlstr forkey:@"stricon"]; [datadic setobject:@"" forkey:@"strmessagestatus"]; messageframe *messageframe = [[messageframe alloc] init]; messageframe.isgroupmessage = _isgroupchat; message *message = [[message alloc] init]; message.issending = yes; if (!istempmessage) { message.messageid = messageid; message.istempmessage=false; } else { message.messageid = tempid; message.istempmessage=true; } message.shownotsendbutton = no; message.delegate = _chatroomvc; [message setwithdict:datadic]; if (!istempmessage) { nsdictionary *mqdict=@{@"message":messagestring,@"target":targetstring,@"messagetype":@(messagetype),@"messageid":messageid}; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, 0),^{ nsdictionary *messagedict=[message dictionarywithpropertiesofobject:message]; nslog(@"messagedict=%@",messagedict); // save temp db nslog(@"message object=%@",message); nslog(@"mqdic=%@",mqdict); nslog(@"messagedic=%@",messagedict); nsstring *msgid=mqdict[@"messageid"]; nsdictionary *tempmessage=@{@"messageid":msgid,@"topic":topicstring,@"mqdict":mqdict,@"messagedict":messagedict,@"timestamp":[nsstring stringwithformat:@"%.0f",timestamp]}; if (![[fmdbmanager sharedinstance] didtempmessageexistwithmessageid:msgid]) { [[fmdbmanager sharedinstance] savetempmessage:tempmessage]; } }); // use tempid if (isusingtempmessage) { nslog(@"usingtempmessage"); // path tempmessage nslog(@"reftempid=%@",reftempid); message *tempmessage=[self querymessage:reftempid]; if (tempmessage!=nil) { // set file path of message nsstring *filepath=tempmessage.picture; message.filepath=filepath; } } } else { } bool isshowtime = [message minuteoffsetstart:previoustime end:datadic[@"strtime"]]; messageframe.showtime = isshowtime; messageframe.showiconenable = self.showiconenable; messageframe.showselfnameenable = self.showselfnameenable; messageframe.showfriendsnameenable = self.showfriendsnameenable; [messageframe setmessage:message]; /*************** layout ***************/ nslog(@"istempmessage=%d",istempmessage); if (istempmessage) { nslog(@"message=%@",message); } if (isusingtempmessage) { nslog(@"replace temp message %@ on screen",reftempid); [self replacemessage:reftempid withmessageframe:messageframe]; } else { nslog(@"show message on screen"); //charles edit 8/8 messageframe *msgframe = self.datasource.lastobject; previoustime = msgframe.timestampstr; [self.datasource addobject:messageframe]; } }
there many approaches task these 2 professional way.
1: create custom delegate protocols , pass data delegate methods.
2: use ios blocks task.
you can use approach think easy , simple.
Comments
Post a Comment