'터치'에 해당되는 글 1건

  1. 2012.09.13 UIImageView 터치 이벤트
iOS2012. 9. 13. 13:49

UIImageView를 터치했을 경우의 이벤트를 얻어야 할 경우.
UIControl을 이용해 이벤트를 얻어온다.

1. UIImageView 생성.
2. UIControl 타입의 mask 생성.
3. mask 에 imageView 자식 뷰로 추가
4. mask 에 이벤트 설정.
5. 현재의 뷰컨트롤러의 뷰에 자식뷰로 mask 추가.



    UIImage * image = [UIImage imageNamed:@"sexy.jpg"];

    UIImageView * imageView = [[[UIImageView allocinitWithImage:image] autorelease];

    [imageView setFrame:CGRectMake(10.0f10.0f90.0f90.0f)];

    [imageView.layer setBorderColor:[[UIColor grayColorCGColor]];

    [imageView.layer setBorderWidth:1.0];

    [imageView.layer setCornerRadius:10.0];

    [imageView.layer setMasksToBounds:YES];

    

    UIControl * mask = [[[UIControl allocinitWithFrame:imageView.frameautorelease];

    

    CGSize imageSize = imageView.frame.size;

    imageView.frame = CGRectMake(00, imageSize.width, imageSize.height);

    [mask addSubview:imageView];

    

    [mask addTarget:self action:@selector(cancelButtonPush:) forControlEvents:UIControlEventTouchUpInside];

    

    [self.view addSubview:mask];

Posted by 다오나무