1
위치를 처리하는 NSObject 클래스가 있으며 특정 지점에서 UIView가 표시되어 지속적으로보기가 업데이트 된 다음 숨겨집니다. 가장 좋은 방법은 NSObject에서 UIWindow 위에 UIView를 숨기고 있습니까?
나는addSubview
와 함께 몇 가지 방법을 시도 :
[UIApplication sharedApplication].keyWindow
[UIApplication sharedApplication].windows.firstObject
어떻게 든 그것이를 업데이트하지 않는 일부 값 I 업데이트 (지점으로부터의 거리가 가리 키도록)이 UIView의 상단에 UILabel의를했습니다 더 이상보기, 그것은 한 번 나타나고 thats 및 그것을 숨기지 않는다.
내 코드 : 나는 여기에서 뭔가 잘못하고 있어요
// Updates the UIView from 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];
// The function inside the UIView that updates the UILabel and it 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 TO 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 that removes the UIView
- (void)dismiss
{
[self removeFromSuperview];
[[UIApplication sharedApplication].keyWindow setNeedsLayout];
}
?
결국 NSView 클래스에서 보여줄 UIView 또는 UIViewController가 필요한지 여부. –
@IdanMoshe UIViewController와 NSObject 클래스 사이에서 통신하기 위해 델리게이트 함수를 설정할 수 있습니다. '제시된 UIVIewController'를 사용하여 동적 인 내용을 보여주는 것은 당신이 현재하고있는 것과 크게 다르지 않습니다. –