Ios 单击下一步按钮时清除触摸屏uiimageview
如何删除填充颜色 我的代码:Ios 单击下一步按钮时清除触摸屏uiimageview,ios,Ios,如何删除填充颜色 我的代码: - (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", @
- (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];
}
-(void)viewDidLoad{
[超级视图下载];
alphabetsStoreArray=[[NSMutableArray alloc]initWithObjects:
@“write a.png”、@“write b.png”、@“write c.png”,
@“写入d.png”、“写入e.png”、“写入f.png”,
@“写入g.png”、“写入h.png”、“写入i.png”,
@“write j.png”、@“write k.png”、@“write l.png”,
@“写入m.png”、@“写入n.png”、@“写入o.png”,
@“write p.png”、@“write q.png”、@“write r.png”,
@“写入s.png”、“写入t.png”、“写入u.png”,
@“write v.png”、@“write w.png”、@“write x.png”,
@“write y.png”,@“write z.png”,nil];
_homePopupView.hidden=true;
[姓名];
}
-(无效)姓名{
_语音=@“en-US”;
_速度=.25华氏度;
如果(计数>=alphabetsStoreArray.count)
{
printf(“%d”,计数);
NSLog(@“完成”);
[_alphabetChangeImageView从SuperView移除];
[_alphabetBackgroundImageView从SuperView移除];
}
否则如果(计数50&&location.y<\u alphabetBackgroundImageView.frame.size.height-50))
{
lineImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,100,100)];
lineImageView.center=位置;
lineImageView.backgroundColor=所选颜色;
[\u alphabetBackgroundImageView添加子视图:lineImageView];
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件
{
//向路径添加新点
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint位置=[触摸位置视图:_alphabetBackgroundImageView];
if((location.x>50&&location.x 50&&location.y<\u alphabetBackgroundImageView.frame.size.height-50))
{
lineImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,100,100)];
lineImageView.center=位置;
lineImageView.backgroundColor=所选颜色;
[\u alphabetBackgroundImageView添加子视图:lineImageView];
}
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event
{
NSSet*touchesForTargetView=[事件touchesForView:self.alphabetBackgroundImageView];
if(touchesForTargetView.allObjects.count!=0){
NSLog(@“是”);
//触摸是在目标视图
}
否则{
NSLog(@“否”);
//触摸是在别的地方
}
}
-(void)speechSynthesizer:(AVSpeechSynthesizer*)合成器didStartSpeechUtterance:(AVSpeechUtterance*)话语{
[自动按钮操作];
_next.enabled=是;
}
-(void)speechSynthesizer:(AVSpeechSynthesizer*)合成器didCancelspeechoutrance:(avspeechoutrance*)话语{
//相应地启用/禁用按钮
[自动按钮操作];
_retry.enabled=否;
计数+=1;
[姓名];
}
-(void)speechSynthesizer:(AVSpeechSynthesizer*)合成器将SpeakRangeofSpeechString:(NSRange)characterRange话语:(avSpeechOutrance*)话语{
//获取文本
NSString*text=[话语speechString];
//应用属性
NSMutableAttributedString*all=[[NSMutableAttributedString alloc]initWithString:text];
[所有addAttribute:NSForegroundColorAttributeName值:[UIColor redColor]范围:characterRange];
//将属性文本设置为textView
[[U tvTextToSpeak setAttributedText:all];
}
-(iAction)nextAction:(id)发送方{
如果([[u合成器正在峰值]){
[_合成器停止语音边界:AVSpeechBoundaryImmediate];
[自动按钮操作];
_next.enabled=否;
[u tvtextospeak setText:speechString1];
}
计数++;
[姓名];
}
这里我有两个imageview 1.aplhabetbackground 2.alphabetchangingbackground
因此,根据我的代码,当“下一步”按钮单击字母表存储阵列中的第二个数据时,其图像将显示在imageview中。点击“下一步”按钮,它会显示下一张图片,等等
这里我在字母表背景中使用了触摸事件。所以当图像显示时,我可以在屏幕上触摸并填充选定的颜色
但我需要在单击下一步按钮时,将填充的颜色从中删除。如何执行如何清除子视图触摸图像视图如何可以查看
lineImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,100,100)]代码>你每次都在创建一个新实例?我想它应该是一个全局变量,并且只初始化一次。WelllineImageView.backgroundColor=[UIColor clearColor]代码>将删除其颜色。