سؤال

I am not sure if this is an iOS 7 bug or what. But..I cannot get the UIAccessibilityInvertColorsStatusDidChangeNotification to work.

So when I init my nib I do this:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(inverted)
                                                     name:UIAccessibilityInvertColorsStatusDidChangeNotification
                                                   object:nil];
    }
    return self;
}

Later in my code I have the notification:

- (void)inverted {
    if(UIAccessibilityIsInvertColorsEnabled()) {
        NSLog(@"setting tintcolor to cyan");
        self.view.tintColor = [UIColor cyanColor];
        [self tintColorDidChange];
    } else {
        NSLog(@"setting tintcolor to red");
        self.view.tintColor = [UIColor redColor];
        [self tintColorDidChange];
    }
}

However when my app is running and I change the Invert Colors mode via tripple-tap on the home button, nothing happens in the app. Don't get a message on console, don't get a change of tintColor, don't get nothin'.

I tested this on iOS 6 and iOS 7. I tried setting my build target for iOS 6.1 instead of 4.3 and that didn't fix it either.

I tried adding -(void)inverted; to my interface and that didn't fix it. I tried adding the colon after inverted but that didn't fix it either, and the docs say that this notification doesn't have an argument anyway.

Obviously I'm doing something wrong. What? Thanks in advance.

هل كانت مفيدة؟

المحلول

Weird... must be a bug but...

all I had to do in order to fix this was to call

UIAccessibilityIsInvertColorsEnabled();

inside the viewDidLoad method of the viewController. After I added that one line of code, now the notifications come through just fine (although there is still one frame of display where it's displayed wrong). Evidently the inverted colors notifications don't get observed at all unless you call this first. Apple's documentation doesn't tell you this.

Definitely one of the weirder things I've come across.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top