2010-05-17 4 views
1

저는 iPhone과 iPad 개발에서 상당히 n00b입니다. 따라서 모든 조언을 기꺼이 받아 보겠습니다.iPad 분할 뷰 앱에서 드래그 앤 드롭을 구현 하시겠습니까?

사용자가 루트보기 컨트롤러에서 이미지를 드래그하여 상세보기에 배치 할 수있는 분할보기 iPad 앱을 만들고 싶습니다.

일단 끝나면 이상적으로 사용자는 이미지를 이동하고 크기를 조정하여 이미지를 조작 할 수있게됩니다.

이것을 수행하는 가장 좋은 방법에 대한 지침이 있습니까? 많은 감사합니다!

답변

1

처음에는 새 책을 가져 오는 것이 좋습니다. 내 것은 입니다. iPhone 4 개발 시작
Dave Mark, Jack Nutting 및 Jeff LaMarche (Apress). 그것은 많은 시간을 낭비하고 시작하기 위해 나를 구했습니다. 또한 필요한 책에는 더 적합한 책이 있지만이 책에는 도청, 터치 및 제스처 (15 : 도청, 터치 및 제스처)라는 꽤 좋은 장이 있습니다. 어쨌든 요점을 heres

:

const UIImageView * viewBeingDragged = nil; 

// in your rootController 
// (lets say a UIViewController with one UIImageView) 
// 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    CGPoint touchPoint = [[touches anyObject] locationInView:self.view]; 

    //our image views are direct decendents of our main view 
    //the following method returns the farthest decendent from the target 
    //in the point, so make sure you dont have any intersecting subviews! 
    //pretty sure you dont need event 
    // 
    UIView *v = [self.view hitTest:touchPoint event:nil]; 
    NSAssert([v isMemberOfClass:[UIImageView class]], @"Not an image view?!?!?"]); 

    viewBeingDragged = (UIImageView *)v; 

    [v removeFromSuperview]; 
    // or just gray it out... 
    [self.view.superview.superview addSubview:v]; 
    //should be your splitViewController, if not get from AppDelegate 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    viewBeingDragged.center = 
     [[touches anyObject] locationInView:SplitControllerView]; 

    if (viewBeingDragged.frame intersects with detailViewController.view.frame) 
    { 
     //visual cue that landing zone is set 
    } 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    // last check if view still intersects 
    // if so move underlieing data from left to right 
    // redraw left view 
    // remove viewBeingDragged from superview 
    // add viewBeingDragged to 
    viewBeingDragged = nil; 
} 

당신은 또한 내가 그렇게 예기치 않은 상황이 올 수도 있습니다 방법을 테스트 havent 한
을 touchesCanceled 구현할 수 있습니다.
또한 UIView에는 동일한 터치 방법이 있으므로 사용자가 자신 만의 사용자 지정보기 /보기 컨트롤러를 만들어 확장 성을 향상시키려는 경우.

관련 문제