ios - removeFromSuperview() takes too long -
i try save object viewcontroller.swift core data after picking image imagepickercontroller. display view (dynamicview) spinner while saving. object saved in 1 or 2 seconds, dynamicview takes 7 or 8 seconds removed superview.
func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [nsobject : anyobject]){ dismissviewcontrolleranimated(true, completion: nil) picture = info[uiimagepickercontrolleroriginalimage] as? uiimage view.addsubview(dynamicview) var newimagedata = uiimagejpegrepresentation(picture, 1) objecttosave?.photo = newimagedata progressbardisplayer("test", true) dispatch_async(dispatch_get_global_queue( int(qos_class_user_interactive.value), 0)) { self.save() } } func save() { var error : nserror? if(!managedobjectcontext!.save(&error) ) { println(error?.localizeddescription) }else{ println("no error, saved") self.dynamicview.removefromsuperview() } nsnotificationcenter.defaultcenter().postnotificationname("load", object: nil) }
call removefromsuperview() main thread make sure ui synchronized:
func save() { var error : nserror? if(!managedobjectcontext!.save(&error) ) { println(error?.localizeddescription) }else{ println("no error, saved") dispatch_async(dispatch_get_main_queue(),{ self.dynamicview.removefromsuperview() } } nsnotificationcenter.defaultcenter().postnotificationname("load", object: nil) }
Comments
Post a Comment