标签: touchesbegan

如何在iphone中触摸或挤压tableView单元?

我有一个tableView完成填充视图.当我点击一个单元格表时查看:didSelectRowAtIndexPath:被解雇了,但是当我写了touchesBegan:withEvent来查找tableView的触摸和Pinch事件时它没有被触发.Tableview上面的视图是没有触发的原因,如果是,当tableView或其某个单元格被触摸或收缩时如何查找.


我找到了一种在Table View单元格中找到Pinch或touch的方法,首先在tableView中声明UIPinchGestureRecognizer对象:didSelectRowAtIndexPath:ie

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
[tblAccountsList addGestureRecognizer:pinch];
[pinch release];
Run Code Online (Sandbox Code Playgroud)

然后写下面的选择器方法......

- (void)handlePinch:(UIGestureRecognizer *)recognizer {
    NSLog(@"Pinch");
}
Run Code Online (Sandbox Code Playgroud)

当我设置断点时它正在执行,但该方法被调用了3次.如果有人发现解决方案请分享它...

提前致谢...

uitableview uitouch pinch touchesbegan

3
推荐指数
1
解决办法
5426
查看次数

UIScrollView子类从不接收用于滑动的touchesBegan消息

我试图使滚动视图只能在某个区域上滚动.为此,我将UIScrollView子类化并覆盖touchesBegan(类似于这个问题).

这是我(非常简单)的代码.

.H

 @interface SuppressableScrollView : UIScrollView
 @end
Run Code Online (Sandbox Code Playgroud)

.M

#import "SuppressableScrollView.h"

@implementation SuppressableScrollView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesBegan touches=%@ event=%@", touches, event);
    [super touchesBegan:touches withEvent:event];
}

@end
Run Code Online (Sandbox Code Playgroud)

touchesBegan仅被调用UIScrollView通常不会消耗的触摸(如点击).知道怎么拦截所有的触摸?

我想我在某个地方错过了一个概念.

uiscrollview touchesbegan ios

3
推荐指数
1
解决办法
1575
查看次数

pressGestureRecognizer和touchesBegan

我有以下问题.我正在使用一个UILongPressGestureRecognizerUIView进入"切换模式".如果UIView处于"切换模式",则用户可以在屏幕上拖动UIView.为了在屏幕上拖动UIView我正在使用方法touchesBegan,touchesMovedtouchesEnded.

它工作,但是:我必须举起手指才能拖动它,因为该touchesBegan方法已被调用,因此不会再次调用,因此我无法拖动UIView屏幕.

触发touchesBegan后是否有任何方法可以手动调用UILongPressGestureRecognizer(UILongPressGestureRecognizer更改BOOL值,touchesBegan仅当此BOOL设置为YES时才有效).

cocoa cocoa-touch touchesbegan ios

3
推荐指数
1
解决办法
3734
查看次数

viewDidLayoutSubviews在touchesBegan之后调用 - 一次又一次

iPhone文字游戏中,我有一个UIScrollView(持有UIImageView)和7个可拖动的自定义UIViews,最初放在底部(滚动视图外):

应用截图

在单个ViewController.m中,我已经覆盖了viewDidLayoutSubviews所以它总是设置zoomScale滚动视图 - 使UIImageView填充恰好100%的屏幕宽度.

这适用于纵向和横向模式.当应用程序刚刚启动时:

肖像

景观

问题是,当我第一次捏合/缩放/双击滚动视图然后移动七个Tile.m视图中的一个时:

突然(不是每次)都viewDidLayoutSubviews被称为touchesBegan.

这会重置滚动视图的缩放 - 意外地为用户.

我的问题是,是否有任何方法可以禁用此行为?

viewDidLayoutSubviews当孩子UIView被触摸/拖动时,是否可以阻止父母的呼叫?

更新:

我已经将zoomScale设置代码移动viewDidLayoutSubviewsdidRotateFromInterfaceOrientation了,滚动视图缩放现在可以了,但它contentOffset被重置为{0,0},当(不总是)我拖动Tile时 - 即滚动视图突然跳跃,应用程序无法使用.

添加以下内容viewDidLoad没有帮助:

if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)])
   self.automaticallyAdjustsScrollViewInsets = NO;
Run Code Online (Sandbox Code Playgroud)

iphone uiscrollview uiimageview touchesbegan ios

3
推荐指数
1
解决办法
4402
查看次数

如何检测touchesBegan,touchesMoved,touchesEnded来自另一个类的事件

我需要使用触摸事件,但我试图从另一个类中检测它,所以如果触摸或移动等我将回调我的主类.我首先在"classTouchEvents"中调用init方法,首先从我的主类中调用

objectTouchEvents=[[classTouchEvents alloc]initWith:self.view];
Run Code Online (Sandbox Code Playgroud)

这是initWith"classTouchEvents"的方法

 - (id)initWith:(UIView *)selfView
{
    self = [super init];
    if (self) {
        NSLog(@"here");
        view=[[UIView alloc]init];
        view=selfView;
        // Custom initialization
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

我得到"这里"日志,所以我猜它正在工作,但我无法检测视图是否触摸或任何东西.这是我在classTouchEvents中的触摸事件

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

    NSLog(@"touchBegan");
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
 NSLog(@"touchMoved");
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchEnded");
}
Run Code Online (Sandbox Code Playgroud)

但我无法得到关于触摸的任何日志.我需要一些帮助.提前致谢.

objective-c touchesmoved touchesbegan touch-event ios

3
推荐指数
2
解决办法
1万
查看次数

UIView没有得到touchesbegan的称呼

还有其他一些问题,但没有一个解决方案似乎对我有用.我是iOS的新手 - 目前正在研究Big Nerd Ranch iOS编程书中的一个问题.

我发现的大多数SO都说这个问题最终userInteractionEnabled = YES失踪了.或者视图的背景设置为transparent.但删除透明背景和设置userInteractionEnabled = YES不会导致事件触发.我缺少什么想法?

AppDelegate.m:

#import "AppDelegate.h"
#import "BNRHypnosisView.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    CGRect firstFrame = self.window.bounds;

    BNRHypnosisView *firstView = [[BNRHypnosisView alloc] initWithFrame:firstFrame];
    firstView.userInteractionEnabled = YES;

    ViewController *controller = [[ViewController alloc] init];
    [self.window setRootViewController:controller];
    [self.window addSubview:firstView];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible]; …
Run Code Online (Sandbox Code Playgroud)

objective-c uiview touchesbegan ios

3
推荐指数
1
解决办法
965
查看次数

使用touchesmoved时,Touchesbegan总会开火吗?

我是iPhone编程的新手.我正试图做一个简单的窗口,一只猫做两声.当你点击猫图标时它应该做"miaau",当你拖过窗口(笔划)时它应该是"mrrrr".它工作,但总是当我尝试使猫mrrrrr功能TouchesBegan火和猫也做"miaaau".

怎么做才能使界面识别我只想要中风猫,而不是触摸它做第一个选项,"miaau"?

iphone touchesmoved touchesbegan

2
推荐指数
1
解决办法
855
查看次数

Touchesbegan没有检测到被触摸的内容

我正在使用NSTimer构建一个旋转横幅来跟踪当前图像,图像是从5个不同的图像中动画出来的.我有一个touchesBegan设置,如果有人点击它,继续处理横幅上的触摸事件.我的概念验证工作,但将其转移到另一个项目,它打破了.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
if ([touch view] == myImageView){
    [self getImage];
    NSLog(@"%@", currentImage);
}
}
Run Code Online (Sandbox Code Playgroud)

现在,当我将断点放入我的项目时,它可以很好地抓住触摸,但是当它到达if([触摸视图] == myImageView)时,它不会检测到正在触摸图像视图.

iphone touch imageview touchesbegan ios

2
推荐指数
1
解决办法
7838
查看次数

检测触摸了SKSpriteNode的哪个实例?

我正在使用此代码来检测并查看用户是否在我的SKSpriteNode框架内,如果是,则从屏幕中删除该节点.但我只希望被点击的节点消失.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */

    for (UITouch *touch in touches) {
            CGPoint location = [touch locationInNode:self];

        if ((location.x > self.crate.frame.origin.x && location.x < self.crate.frame.origin.x + self.crate.frame.size.width) &&
            (location.y > self.crate.frame.origin.y && location.y < self.crate.frame.origin.y + self.crate.frame.size.height)) {

            [self.crate removeFromParent];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的update方法中,我调用一个方法addCrate:每秒生成一个节点.

- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast {

    self.lastSpawnTimeInterval += timeSinceLast;
    if (self.lastSpawnTimeInterval > 1) {
        self.lastSpawnTimeInterval = 0;
        [self addCrate];
    }
}

- (void)update:(NSTimeInterval)currentTime {
    // Handle time delta.
    // If we drop …
Run Code Online (Sandbox Code Playgroud)

touchesbegan sprite-kit skspritenode

2
推荐指数
1
解决办法
5692
查看次数

UIWindow子类:触摸事件未被触发

我想在当前项目中实现会话时间功能.所以为此我尝试子类化UIWindow并覆盖touchesBegantouchesEnded方法.

class BaseWindow: UIWindow {

    convenience init() {
        self.init(frame: UIScreen.mainScreen().bounds)
    }

    private var sessionTimeOutTimer: NSTimer?

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        sessionTimeOutTimer?.invalidate()
    }

    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        sessionTimeOutTimer = NSTimer.scheduledTimerWithTimeInterval(60, target: CIAppManager.sharedManger(), selector: #selector(CIAppManager.sessionTimeOut), userInfo: nil, repeats: false)
    }
}
Run Code Online (Sandbox Code Playgroud)

在app委托中,我做到了这一点

private let baseWindow = BaseWindow()
var window: UIWindow? {
    get {
        return baseWindow
    }
    set {}
}
Run Code Online (Sandbox Code Playgroud)

但问题是touchesBegan,touchesEnded并没有得到调用.我无法弄清楚我做错了什么.

uiwindow touchesbegan ios swift touchesended

2
推荐指数
1
解决办法
835
查看次数