I just finished Stanford’s iPhone lesson that uses AVFoundation. It was the class where the TA had us make an App that displayed video and then put sunglasses on the face with face recognition. So I wanted to hook up a couple of switches and sliders to do different things. The first was a slider that changed the value of the hue filter. Then I wanted to make a switch to show the sunglasses or not. But the switch does not turn the sunglasses off. Although the switch works. I declared a BOOL in the properties with
@property (nonatomic) BOOL sunGlasses;
I synthesized it and then hooked the switch up to the following action
- (IBAction)toggleGlasses:(id)sender
{
if (_mySwitch.on)
{
NSLog(@"toggle is on");
self.sunGlasses = YES;
}else {
NSLog(@"toggle is off");
self.sunGlasses = NO;
}
}
Then under the method for -(void) captureOutput, that is where the hue gets changed and the face recognition is I added to the face recognition portion
if ((faceFound) && (self.sunGlasses = YES)){
[self.glasses setHidden:NO];
}else{
[self.glasses setHidden:YES];
}
It used to be just if (faceFound) and then hid the glasses or showed them. However, this does not make the glasses go away if you switch the switch to off.
You used:
The single = is an assignment. It sets the value of that property, and when this statement is used within a larger expression it’s value is YES. So the “if” condition is always true and the branch that shows sunglasses is always taken.
Use the double equals == to test for equality.