i have uiactionsheet
selecting between camera or photo library embed image uitextview
whatever reason it's loading keyboard. force close keyboard on press of left button of bar surrounding uitextview
when press photo library opens , closes keyboard before pushing image picker vc.
override func didpressleftbutton(sender: anyobject?) { let cameramenu = uialertcontroller(title: nil, message: nil, preferredstyle: .actionsheet) let photolibrary = uialertaction(title: "photo library", style: .default, handler: { (uialertaction) in self.openphotolibrary() }) let takephoto = uialertaction(title: "open camera", style: .default, handler: { (uialertaction) in self.textview.endediting(true) self.opencamera() }) let cancel = uialertaction(title: "cancel", style: .cancel, handler: nil) cameramenu.addaction(photolibrary) cameramenu.addaction(takephoto) cameramenu.addaction(cancel) self.presentviewcontroller(cameramenu, animated: true, completion: nil) } func openphotolibrary() { imagepicker.sourcetype = .photolibrary imagepicker.allowsediting = false presentviewcontroller(imagepicker, animated: true, completion: nil) } func opencamera(){ imagepicker.sourcetype = .camera imagepicker.showscameracontrols = true presentviewcontroller(imagepicker, animated: true, completion: nil) } func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string : anyobject]) { if let pickedimage = info[uiimagepickercontrolleroriginalimage] as? uiimage { // image resizing let textviewwidth: cgfloat = self.textview.frame.size.width - 20 let percentresize = textviewwidth / pickedimage.size.width let tobeexportedheight = pickedimage.size.height * percentresize let resizedimage = imagemanipulationmanager.sharedinstance.resizeimage(exportedwidth: int(textviewwidth),exportedheight: int(tobeexportedheight), originalimage: pickedimage) // storage textview let attachment = nstextattachment() attachment.image = resizedimage let attstring = nsattributedstring(attachment: attachment) textview.textstorage.insertattributedstring(attstring, atindex: textview.selectedrange.location) pastedimagelocations.append(textview.selectedrange.location) textview.selectedrange.location = textview.selectedrange.location + 1 textview.textstorage.insertattributedstring(nsattributedstring(string: "\n"), atindex: textview.selectedrange.location) textview.selectedrange.location = textview.selectedrange.location + 1 textview.font = uifont.systemfontofsize(16.0) // image caching if let data = uiimagejpegrepresentation(pickedimage, 0.50) { socketmessages.append(["data": data]) haneke.set(value: data, key: string(unsafeaddressof(attachment.image!))) print("image cached \"\(string(unsafeaddressof(attachment.image!)))\"") } } dismissviewcontrolleranimated(true, completion: nil) self.textview.becomefirstresponder() }
found solution.
i had change
dismissviewcontrolleranimated(true, completion: nil) self.textview.becomefirstresponder()
to
dismissviewcontrolleranimated(true) { self.textview.becomefirstresponder() }
Comments
Post a Comment