처음에는 새 책을 가져 오는 것이 좋습니다. 내 것은 입니다. 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에는 동일한 터치 방법이 있으므로 사용자가 자신 만의 사용자 지정보기 /보기 컨트롤러를 만들어 확장 성을 향상시키려는 경우.