4

我想以我是 iphone 应用程序开发的新手这一事实作为这个问题的序言,并且很多时候我相信我可能已经过头了。我正在尝试找到一个操作,该操作允许我双击全屏 UIScrollView 中的任意位置以返回我的主菜单 (MainMenuViewController)。

我目前正在为我的 ScrollViewController 运行以下代码...

ScrollViewController.h

#import <UIKit/UIKit.h>

@interface ScrollViewController : UIViewController <UIScrollViewDelegate>
{

}

@end

ScrollViewController.m

#import "ScrollViewController.h"

UIScrollView *myScrollView;
UIPageControl *myPageControl;

@implementation ScrollViewController

- (void)loadScrollViewWithPage:(UIView *)page
{
int pageCount = [[myScrollView subviews] count];

CGRect bounds = myScrollView.bounds;
bounds.origin.x = bounds.size.width * pageCount;
bounds.origin.y = 0;
page.frame = bounds;
[myScrollView addSubview:page];
}

...etc

任何建议或示例代码在 ScrollView 控制器中实现双击以允许我返回到我的 MainMenuViewController 将不胜感激。还请包括对视图的任何 Interface Builder 更改(如有必要)。几天来我一直在论坛上倾诉,但未能成功实施此操作。谢谢...RJ

4

1 回答 1

1

首先,创建一个 UIScrollView 的子类:

#import <UIKit/UIKit.h>

@interface MyScrollView : UIScrollView {
}

@end

实现它:

#import "MyScrollView.h"

@implementation MyScrollView

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {

    if (!self.dragging) {
        [self.nextResponder touchesEnded: touches withEvent:event]; 
    }       
    [super touchesEnded: touches withEvent: event];
}

- (void)dealloc {
    [super dealloc];
}


@end

然后,在主视图控制器中使用这个子类而不是普通的 UIScrollView。这将调用 touchesEnded:withEvent: 方法(或者,您可以调用任何您想要的方法)。然后,跟踪双击(如果您需要有关如何执行此操作的信息,请告诉我)。

于 2010-11-30T16:42:04.933 回答