ios - Best way present and hide UIView on top of UIWindow from NSObject? -
i've nsobject class handle locations , in specific point shows uiview , updates view , hides , vice versa.
i tried few methods addsubview
:
[uiapplication sharedapplication].keywindow [uiapplication sharedapplication].windows.firstobject
i've uilabel on top of uiview updates value (distance point point), somehow doesn't updates view anymore, shows once , thats , doesn't hides back.
my code:
// updates uiview nsobject class: nsmutabledictionary *params = [[nsmutabledictionary alloc] init]; params[@"distance"] = @(distancetotrap); params[@"traptype"] = @(trap.gettraptype); params[@"trapid"] = @(trap.gettrapid); trapalarmactivity = [[trapalarm alloc] initwithuserinfo:params]; [trapalarmactivity setneedsdisplay]; [trapalarmactivity.screenview setneedsdisplay]; [[uiapplication sharedapplication].keywindow addsubview:trapalarmactivity]; [[uiapplication sharedapplication].keywindow setneedsdisplay]; // function inside uiview updates uilabel , somehow doesn't updates anymore - (void)broadcastlocationchange:(nsnotification*)notification { if (![db istrapalarmopen]) { return; } dispatch_async(dispatch_get_main_queue(), ^{ if (globaltrap == nil) { //globaltrap = [db gettrap_trapid:trapid]; globaltrap = [dbat gettrap_trapid:trapid]; } int distancetotrap = [db gettrapdistance:globaltrap.gettrapid]; if (distancetotrap == 0) { cllocation *originallocation = kservice_context.locationmanager.location; cllocation *traplocation = [[cllocation alloc] initwithlatitude:globaltrap.lat longitude:globaltrap.lon]; distancetotrap = [traplocation distancefromlocation:originallocation]; } nslog(@"trap alarm - trap distance car: %i", distancetotrap); if (stillnotyetkey) { [self changemessageboxwithdistance:distancetotrap]; if (distancetotrap < kfinish_alarm_distance) stillnotyetkey = no; else { if (distancetotrap > lastdistancetotrap) { [self finishtrapalarm]; } else { [self changemessageboxwithdistance:distancetotrap]; } } } // check if user exit polygon before passing trap if (distancetotrap > lastdistancetotrap) { distancegrow++; if (distancegrow >= kcounter_for_close_window_when_distance_grow_user_out) { [self finishtrapalarm]; } } lastdistancetotrap = distancetotrap; [self setneedsdisplay]; [[uiapplication sharedapplication].keywindow setneedsdisplay]; }); } // function removes uiview - (void)dismiss { [self removefromsuperview]; [[uiapplication sharedapplication].keywindow setneedslayout]; }
i'm doing wrong in here?
in case want present , dismiss view use presentviewcontroller
, dismissviewcontroller
same. changing keywindow
not advised.
Comments
Post a Comment