2010-05-17 79 views
1

我在iPhone和iPad的開發中已經有100多人了,所以任何建議都會得到感謝。在iPad分屏視圖應用中執行拖放操作?

我想創建一個拆分式iPad應用程序,用戶可以將圖像從根視圖控制器拖出並放置在詳細視圖中。

一旦完成,理想情況下,用戶將能夠通過移動圖像並調整其大小來操縱圖像。

任何指向實現此目的的最佳方式?非常感謝!

回答

1

那麼首先,如果你的新建議我得到一本書。 Mine是從Dave Mark,Jack Nutting和Jeff LaMarche(Apress)開始iPhone 4開發
。它使我免於浪費大量時間並開始工作。另外,可能會有更適合你需要的書,但是這本書有很多關於水龍頭,觸摸和手勢的章節......叫做15:水龍頭,觸摸和手勢。

反正繼承人的要點:

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; 
} 

您可能還需要實現touchesCanceled
我還沒有測試這種方法太意外的事情可能出現。
此外,UIView具有相同的觸摸方法,所以如果你想創建自己的自定義視圖/視圖控制器,使其更加......「可擴展」。