2012-10-20 3 views
0

가능한 중복을 두드리고있어 어떤 이미지가 감지되지 않는 이유 :
Tracing the exact location of the longpressgesture with CGPoint그것이 내가

그것은 항상 이미지 NSLog0를 누를 수 있습니다. 나는 정확히 무엇이 잘못되었는지 이해하지 못합니다. 그것은 제가 누리고있는 이미지의 숫자를 결코 제공하지 못합니다. 내가 이미지를 저장하려고 할 때에도 나는 항상 마지막 이미지를 저장합니다.

- (void)viewDidLoad 

{ 

UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
imageScrollView.delegate = self; 
imageScrollView.pagingEnabled = YES; 
for (int i = 0; i < 61; i++) { 

    CGFloat xOrigin = i * self.view.frame.size.width; 

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

    [myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside]; 

    myButton.frame = CGRectMake(xOrigin, 10, 60, 35); 


    [myButton.layer setMasksToBounds:YES]; 

    [myButton.layer setCornerRadius:10.0f]; 

    myButton.layer.borderWidth = 2; 

    myButton.layer.borderColor = [[UIColor whiteColor] CGColor]; 

    [myButton setTitle:@"Done" forState:UIControlStateNormal]; 

    myButton.backgroundColor = [UIColor clearColor]; 

    NSString *imageName = [NSString stringWithFormat:@"image%d.png", i]; 

    _image = [UIImage imageNamed:imageName]; 

    _imageView = [[[UIImageView alloc] initWithImage:_image]autorelease]; 

    _imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height); 




    UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] 
                 initWithTarget:self 
                 action:@selector(handleLongPress:)]; 

    imageScrollView.userInteractionEnabled = YES; 

    [imageScrollView addGestureRecognizer:gestureRecognizer]; 
    gestureRecognizer.delegate = self; 
    [gestureRecognizer release]; 

    [imageScrollView addSubview:_imageView]; 

    [imageScrollView addSubview:myButton]; 

} 

imageScrollView.contentSize = CGSizeMake(_imageView.frame.size.width * 61 , _imageView.frame.size.height); 

[self.view addSubview:imageScrollView]; 

} 

- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer{ 

if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Save Photo", nil]; 
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 
    [actionSheet showInView:self.view]; 
    [actionSheet release]; 

}} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

switch (buttonIndex) { 
    case 0: 

     [self performSelector:@selector(LongPress:) withObject:nil]; 

     break; 

    default: 
     break; 

}} 


- (void)LongPress:(UILongPressGestureRecognizer*)gestureRecognizer{ 


UIView *view = gestureRecognizer.view; 
int index = view.tag; 

//UIImageWriteToSavedPhotosAlbum(index, self, @selector(image: didFinishSavingWithError:contextInfo:), nil); 
    NSLog(@"image pressed %i", index);   
    } 

답변

관련 문제