ios - 开关和 Ifs

标签 ios objective-c iphone

我有一个 slider 可以改变模糊半径:

- (IBAction)sliderValueChangesFinderUp:(id)sender {

_sliderValue = round(self.blurSlider.value);

_effectImage = nil;
_effectImage = [BlurFilter imageByApplyingClearEffectToImage:self.myImage
      withRadius:_sliderValue color:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]];

self.imageView.image = _effectImage; 
}

我还有一个按钮可以改变模糊颜色(部分 - [UIColor colorWith..])

- (IBAction)setColorGreen:(id)sender {

_effectImage = nil;
_effectImage = [BlurFilter imageByApplyingClearEffectToImage:self.myImage 
withRadius:_sliderValue color:[UIColor colorWithRed:0 green:1 blue:0 alpha:0.15]];

self.imageView.image = _effectImage;
}

这个按钮改变了颜色,但是当我想改变模糊半径时,颜色被重置了,我知道这是因为代码 - (IBAction)sliderValueChangesFinderUp:(id)sender

但是我应该如何正确地创建一个 switch 或者 if 以便在按下绿色按钮时模糊颜色发生变化并且我可以在不重新设置颜色的情况下更改模糊半径?

最佳答案

为 UIColor 保留一个类级变量,例如名为 colorObject。在您的函数 - (IBAction)sliderValueChangesFinderUp:(id)sender 中访问该变量并将其设置在您的行中

_effectImage = [BlurFilter imageByApplyingClearEffectToImage:self.myImage
      withRadius:_sliderValue color:colorObject];

而不是从头开始创建一个新的。

在您的函数 - (IBAction)setColorGreen:(id)sender 中,如果需要,修改该 colorObject 变量。

关于ios - 开关和 Ifs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28845003/

相关文章:

ios - removeFromSuperview 函数不能正常工作

objective-c - 如何使用quickdialog实现滑动删除

iphone - 基于允许的以下对象的基于算法的对象排序/重新排序

ios - 以编程方式从另一个详细 View Controller 中的表中推送详细 View Controller

iOS:找不到嵌入式框架,但仅在*某些*安装中

iphone - 如何比较两个 ALAsset?

iphone - 如何以编程方式从 NSString 中删除特定字符?

iphone - 如何在 UITableView 中为自定义单元格使用 UISearchBar

ios - 显示 Entypo 字体中的 5 位基本 Unicode 字符

ios - 如何使用数组作为标题和 AFNetworking 进行 POST