如何在 Xcode 4.3 中成功使用 BOOL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11811679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:08:10  来源:igfitidea点击:

How to successfully use a BOOL in Xcode 4.3

iosxcodebooleanavfoundation

提问by Douglas

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

我刚刚完成了斯坦福大学使用 AVFoundation 的 iPhone 课程。那节课上,TA让我们制作了一个显示视频的应用程序,然后将太阳镜戴在脸上并进行人脸识别。所以我想连接几个开关和滑块来做不同的事情。第一个是更改色调过滤器值的滑块。然后我想切换是否显示太阳镜。但是开关不会关闭太阳镜。虽然开关有效。我在属性中声明了一个 BOOL

@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

然后在 -(void) captureOutput 的方法下,这是改变色调的地方,我将人脸识别添加到人脸识别部分

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.

过去只是 if (faceFound) 然后将眼镜藏起来或显示出来。但是,如果您将开关关闭,这不会使眼镜消失。

回答by rickster

You used:

你用过:

self.sunGlasses = YES

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.

单个 = 是一个赋值。它设置该属性的值,并且当在更大的表达式中使用此语句时,它的值为 YES。因此,“if”条件始终为真,并且始终采用显示太阳镜的分支。

Use the double equals == to test for equality.

使用 double equals == 来测试相等性。

回答by coria7

You can use

您可以使用

if(self.sunGlasses){

如果(self.sunGlasses){

}

}

to validate the

验证