iphone UITextField

UIImageView *pImageView=[[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 pImageView.image=[UIImage imageNamed:@"background.jpg"];


 //給UIImageView添加事件響應
 pImageView.userInteractionEnabled = YES;  //必須爲YES才能響應事件
 UITapGestureRecognizer *singleTouch=[[UITapGestureRecognizer alloc] initWithTarget:self 
                    action:@selector(MakeKeyboardDisappear:)];
 [pImageView addGestureRecognizer:singleTouch];
 [singleTouch release];
 
 pImageView.tag = 0;

 self.BackgroundImageView=pImageView;
 [self.view addSubview:self.BackgroundImageView];
 [pImageView release];


//響應函數
-(void)MakeKeyboardDisappear:(id)sender
{
 NSLog(@"handleImg begin");
 if (isKeybroadActive) 
 {
  for(UIView *temp in [self.view subviews])
  {  
   if (temp.tag==20) //20是UITextField的標籤
   {
    [(UITextField*)temp resignFirstResponder];
    }
  }
 }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章