- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
全部,
我有一个问题,我已经在 StackOverflow(和其他互联网)上查看了所有可能的答案,但我尝试过的所有解决方案都没有任何效果......
我有一个 UIScrollView 和一个 UIImageView 作为 subview 来创建一个板。我可以放大和缩小,效果很好。滚动也很好!
现在,我想将其他 UIImageView(图 block )拖放到 ScrollView 中,并拖放到 ScrollView 之外。但是当我将 UIImageView 放到 ScrollView 中时,我无法拖放 subview 。
我在viewDidLoad中设置了UIScrollView的setCanCancelContentTouches:NO。
我创建了一个子类 TileImageView,并在初始化中将 exclusiveTouch 设置为 YES。
注意:boardImage 是“普通”UIImageView,tile 属于子类!
补充: 当我将 boardImage 的 UserInteraction 设置设置为 NO 时,ScrollView 缩放但未记录 touchBegan。如果我将其设置为 YES,则 ScrollView 不会缩放,但会记录 touchBegan..
所以我保留它以便缩放,但是 Tiles 一旦进入 ScrollView 就不能再拖动了。
我究竟做错了什么?或者我错过了什么?
PS:设置 delaysContentTouches 属性会使滚动不活动,所以这也不是解决方案...
代码:RootViewController_iphone.m
@implementation RootViewController_iphone
@synthesize boardScrollView;
@synthesize dragObject;
@synthesize boardImage;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIImage *image = [UIImage imageNamed:@"greyblue_numbered_15x15_900x900.png"];
self.boardImage = [[UIImageView alloc] initWithImage:image];
self.boardImage.frame = (CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=image.size};
[self.boardScrollView addSubview:self.boardImage];
self.boardImage.userInteractionEnabled = YES;
self.boardScrollView.contentSize = image.size;
self.boardScrollView.userInteractionEnabled = YES;
self.boardScrollView.canCancelContentTouches = NO;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] == 1) {
// one finger
CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
for (UIImageView *iView in self.view.subviews) {
if ([iView isMemberOfClass:[TileImageView class]]) {
if (touchPoint.x > iView.frame.origin.x &&
touchPoint.x < iView.frame.origin.x + iView.frame.size.width &&
touchPoint.y > iView.frame.origin.y &&
touchPoint.y < iView.frame.origin.y + iView.frame.size.height)
{
self.dragObject = iView;
self.touchOffset = CGPointMake(touchPoint.x - iView.frame.origin.x,
touchPoint.y - iView.frame.origin.y);
self.homePosition = CGPointMake(iView.frame.origin.x,
iView.frame.origin.y);
[self.view bringSubviewToFront:self.dragObject];
}
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
CGRect newDragObjectFrame = CGRectMake(touchPoint.x - touchOffset.x,
touchPoint.y - touchOffset.y,
self.dragObject.frame.size.width,
self.dragObject.frame.size.height);
self.dragObject.frame = newDragObjectFrame;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
NSString *tmp = touch.view.description;
CGPoint touchPointScreen = [[touches anyObject] locationInView:self.view];
CGPoint touchPointImage = [[touches anyObject] locationInView:self.boardImage];
CGPoint touchPointBoard = [[touches anyObject] locationInView:self.boardScrollView];
if (touchPointScreen.x > self.boardScrollView.frame.origin.x &&
touchPointScreen.x < self.boardScrollView.frame.origin.x + self.boardScrollView.frame.size.width &&
touchPointScreen.y > self.boardScrollView.frame.origin.y &&
touchPointScreen.y < self.boardScrollView.frame.origin.y + self.boardScrollView.frame.size.height)
{
self.dragObject.frame = CGRectMake(touchPointImage.x - touchOffset.x,
touchPointImage.y - touchOffset.y,
self.dragObject.frame.size.width,
self.dragObject.frame.size.height);
[self.boardImage addSubview:self.dragObject]; // add to image
}
}
代码:TileImageView.m
@implementation TileImageView:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.exclusiveTouch = YES;
}
return self;
}
最佳答案
您已经有了 UIImageView 的子类,因此您可以在子类中执行以下操作:
1-覆盖touchsBegan、didEnd和didMove
2-在这些方法中将它们传递给 super View ,即 UIScrollView
: [self.superview touchsBegan .... ]
3-如果您的 UIImageView 没有收到这些消息,则在 init 添加 self.userInteractionEnabled = YES;
希望这对你有帮助
关于ios - UIScrollView 中 subview 的 touchEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21676227/
将 @HostListener 与明确键入为 TouchEvent 的事件参数一起使用,会导致 Firefox 崩溃并显示以下错误消息: ReferenceError: TouchEvent is n
我有一个 WPF 触摸应用程序,它运行得很好,除了一件事:捕获用户第一次触摸元素时触发的事件。 TouchDown 似乎不起作用,至少没有明显的延迟。当用户将手指滑到元素上时,TouchEnter 工
在我的应用程序中,用户可以开始录制,他们触摸的每个按钮都将保存到一个数组中 例如: "[{"time":1835,"elemId":"bass"},{"time":2553,"elemId":"hig
我正在构建一个具有整页水平和垂直滚动功能的小网站。查看 codepen 演示 here.演示有一个错误,“向左”和“向上”按钮无法正常工作。 “向右”和“向下”按钮工作正常。我只是把它们放在一起向您展
我有一个问题,如果我在字段外按下/触摸 fieldChanged()为具有焦点的字段触发事件。 我的 MainScreen 的布局很简单,就像这样: public class myMainScreen
TouchEvent.supported尝试创建TouchEvent以确定触摸支持。这适用于实际的触摸设备,但是在使用Chromium DevTools:“模拟触摸屏”时无济于事。 Chromium确
我有几个关于 ADB 的问题。 我尝试运行以下批处理文件: adb wait-for-devices adb shell sendevent /dev/input/event9 3 53 67 adb
我正在开发一个移动应用程序,并且在各种元素上有很多触摸事件。不幸的是,我无法在我的电脑浏览器上测试我的应用程序,因为它不支持 touchevents。如果我在 PC 上运行(当然是通过检查用户代理),
好的,所以在业余时间创建游戏时,我在尝试围绕以下场景编写代码时完全陷入困境: 我想捕获点击事件 (TouchEvent.ACTION_DOWN),然后以 500 毫秒为间隔,我想检查屏幕是否仍被按下,
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
您好,我正在开发一个应用程序,在该应用程序中,我在 Activity 中使用对话框。对话框将只显示一张图片,当用户触摸图片时,对话框应该关闭,启动对话框的 Activity 应该出现在前面。 对话框没
这应该很简单吧?! 因此,我有一个 Gameobject 作为按钮,我在扩展 SurfaceView 的 GamePanel 上引用它,如下所示: bby = new Buttons(BitmapFa
需要在桌面浏览器上使用移动设备模拟来自动化测试。 如果通过ChromeOptions()启用模拟,则触摸屏的模拟不起作用(按钮响应光标等)。这就是为什么我使用 java.awt.Robot (F12
我在尝试从 BB10 级联 API 获取触摸事件的目标时遇到问题。我有几个容器,一个在另一个下面,每个容器都分配了相同的 Touch 信号和插槽。一切都从 C++ 动态加载。因此,为了捕捉每个触摸事件
我有一个自定义 View ,其中我具有触摸事件功能(滑动等)。现在可能会发生这种情况,即在 ScrollableLayout 中使用此自定义 View 。那么问题是,当用户在我的自定义 View 内滑
我的布局看起来像这样: ViewPager 内部有许多 Fragment,每个 Fragment 都有一个 ListView。 现在我想这样做: 通过向下滚动,ListView 不得滚动。相反,必须转
我想在我的 Android 应用程序任何时候触摸屏幕时接收 TouchEvent。即使我的应用程序不在焦点中。 是否有我可以编写的通用事件监听器或 Intent 过滤器来实现此目的? 目标是编写系统范
我有一个 Angular 8 项目,我想在其中处理触摸事件。示例处理程序: @HostListener('touchend', ['$event']) onTouchend(event: TouchE
我正在为一个函数写一个测试 MyFuntion并调用另一个函数sendTouchEvent实例化一个TouchEvent。 function sendTouchEvent(element, event
我正在考虑一个易于使用的 android 可用性测试工具,它将允许用户在应用程序测试期间记录和记录相关信息。作为第一个结果,我希望每次用户与触摸屏交互时截取屏幕截图,其中显示了触摸事件的位置、持续时间
我是一名优秀的程序员,十分优秀!