如何删除填充的颜色?
我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
alphabetsStoreArray = [[NSMutableArray alloc]initWithObjects:
@"write a.png", @"write b.png", @"write c.png",
@"write d.png", @"write e.png", @"write f.png",
@"write g.png", @"write h.png", @"write i.png",
@"write j.png", @"write k.png", @"write l.png",
@"write m.png", @"write n.png", @"write o.png",
@"write p.png", @"write q.png", @"write r.png",
@"write s.png", @"write t.png", @"write u.png",
@"write v.png", @"write w.png", @"write x.png",
@"write y.png", @"write z.png", nil];
_homePopupView.hidden=true;
[self names];
}
-(void)names{
_voice = @"en-US";
_speed = .25f;
if(count>= alphabetsStoreArray.count)
{
printf("%d", count);
NSLog(@"finished");
[_alphabetChangeImageView removeFromSuperview];
[_alphabetBackgroundImageView removeFromSuperview];
}
else if(count<alphabetsStoreArray.count||count<-1)
{
items = [[alphabetsStoreArray objectAtIndex:count] componentsSeparatedByString:@"."];
NSString *tempString = [items objectAtIndex:0];
NSArray *tempArray = [tempString componentsSeparatedByString:@" "];
speechString1 = [tempArray objectAtIndex:1];
if ([_synthesizer isPaused]) {
[_synthesizer continueSpeaking];
}
else{
[self speakText:speechString1];
[self textToSpeechAction:alphabetsStoreArray :count :_alphabetBackgroundImageView :_alphabetChangeImageView :isMicPresent];
}
}
}
-(void)textToSpeechAction:(NSMutableArray *)imageStoreArray :(int)counter :(UIImageView *)imageChangeImageView :(UIImageView *)spekerOrMic :(BOOL)isMicPresent
{
_alphabetChangeImageView.image = [UIImage imageNamed:[imageStoreArray objectAtIndex:counter]];
}
- (void)speakText:(NSString*)text{
if(_synthesizer == nil)
_synthesizer = [[AVSpeechSynthesizer alloc] init];
_synthesizer.delegate = self;
AVSpeechUtterance *utterence = [[AVSpeechUtterance alloc] initWithString:text];
utterence.rate = _speed;
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:_voice];
[utterence setVoice:voice];
[_synthesizer speakUtterance:utterence];
}
- (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event
{
// Initialize a new path for the user gesture
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:_alphabetBackgroundImageView];
if((location.x > 50 && location.x < _alphabetBackgroundImageView.frame.size.width-50) && (location.y > 50 && location.y < _alphabetBackgroundImageView.frame.size.height-50))
{
lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
lineImageView.center = location;
lineImageView.backgroundColor = selectedColor;
[_alphabetBackgroundImageView addSubview:lineImageView];
}
}
- (void) touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event
{
// Add new points to the path
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:_alphabetBackgroundImageView];
if((location.x > 50 && location.x <_alphabetBackgroundImageView.frame.size.width-50) && (location.y > 50 && location.y < _alphabetBackgroundImageView.frame.size.height-50))
{
lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
lineImageView.center = location;
lineImageView.backgroundColor = selectedColor;
[_alphabetBackgroundImageView addSubview:lineImageView];
}
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet* touchesForTargetView = [event touchesForView:self.alphabetBackgroundImageView];
if (touchesForTargetView.allObjects.count != 0) {
NSLog(@"yes");
// touch was at target view
}
else {
NSLog(@"no");
// touch was somewhere else
}
}
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance{
[self buttonoperation];
_next.enabled = YES;
}
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance *)utterance{
// Enable/Disable buttons accordingly
[self buttonoperation];
_retry.enabled = NO;
count +=1;
[self names];
}
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance{
// Get the text
NSString *text = [utterance speechString];
// apply attribute
NSMutableAttributedString * all = [[NSMutableAttributedString alloc] initWithString:text];
[all addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:characterRange];
// set the attributed text to textView
[_tvTextToSpeak setAttributedText:all];
}
- (IBAction)nextAction:(id)sender {
if ([_synthesizer isSpeaking]) {
[_synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
[self buttonoperation];
_next.enabled = NO;
[_tvTextToSpeak setText:speechString1];
}
count++;
[self names];
}
这里我有两个imageview 1.aplhabetbackground 2.alphabetchangingbackground。
因此,根据我的代码,当下一个按钮点击来自字母存储阵列的第二个数据时,它的图像将显示在imageview中。所以点击下一个按钮就会显示下一个图像。
这里我在字母表背景中使用了触摸事件。因此,当显示图像时,我可以在屏幕上触摸并填充所选颜色。
但是我需要在点击下一个按钮时填充颜色应该从中删除。怎么做