【问题标题】:Double Tap inside UIScrollView to Another View在 UIScrollView 内双击到另一个视图
【发布时间】:2010-01-29 15:27:04
【问题描述】:

我想以我是 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 更改(如有必要)。几天来我一直在论坛上倾诉,但未能成功实施此操作。谢谢...R.J.

【问题讨论】:

  • 您找到解决方案了吗?

标签: iphone cocoa-touch uikit uiscrollview double-click


【解决方案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: 方法(或者,您可以调用任何您想要的方法)。然后,跟踪双击(如果您需要有关如何操作的信息,请告诉我)。

【讨论】:

    猜你喜欢
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多