海关;“Swipeable”;UIScrollView在iPad上不能正常工作-在iPhone上可以正常工作
我正在努力使我的iPhone应用程序与iPad兼容。用户可以点击或滑动屏幕来激活某些功能,在我的iPhone版本上也可以正常工作。页面上有一个UIScrollView,我将其子类化为“可切换”,即它将所有触摸功能传递给superview:海关;“Swipeable”;UIScrollView在iPad上不能正常工作-在iPhone上可以正常工作,iphone,ipad,uiscrollview,Iphone,Ipad,Uiscrollview,我正在努力使我的iPhone应用程序与iPad兼容。用户可以点击或滑动屏幕来激活某些功能,在我的iPhone版本上也可以正常工作。页面上有一个UIScrollView,我将其子类化为“可切换”,即它将所有触摸功能传递给superview: @implementation SwipeableScrollView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:t
@implementation SwipeableScrollView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self.superview touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
[self.superview touchesMoved:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[self.superview touchesEnded:touches withEvent:event];
}
@end
这在iPhone版本上运行良好,可以传递轻触和滑动手势,但在iPad上,我会出现以下奇怪的行为:
知道为什么这在iPhone上有效而在iPad上不起作用吗?虽然在iPhone上覆盖触摸事件是必要的,因为苹果推出的iPad使这类任务更简单、更容易实现。您可能需要重构代码才能使用它们。问题是,iPad上的UIScrollView会很快取消内容触摸,即使
canCancelContentTouches
设置为否。此外,覆盖-touchesShouldCancelInContentView:
也没有帮助。阅读此处的更多信息:您可以自定义uiscrollView并实现其委托,这样您就可以使用scrollview执行您想要的操作。它与我配合得很好
#import <UIKit/UIKit.h>
@protocol ScrollingDelegate <NSObject>
@required
- (void)scrolltouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)scrolltouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)scrolltouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@end
#导入
@协议滚动委托
@必需的
-(void)滚动触摸开始:(NSSet*)触摸事件:(UIEvent*)事件;
-(无效)滚动触摸移动:(NSSet*)触摸事件:(UIEvent*)事件;
-(void)scrolltouchesEnded:(NSSet*)触摸事件:(UIEvent*)事件;
@结束
实施
@interface CustomScrollView : UIScrollView
{
id <ScrollingDelegate> delegate;
}
@property (nonatomic,strong) id scrollDelegate;
@end
#import "CustomScrollView.h"
@implementation CustomScrollView
@synthesize scrollDelegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self=[super initWithCoder:aDecoder];
if (self)
{
}
return self;
}
-(BOOL)touchesShouldCancelInContentView:(UIView *)view
{
return NO;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.scrollDelegate scrolltouchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.scrollDelegate scrolltouchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.scrollDelegate scrolltouchesEnded:touches withEvent:event];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
@end
@interface CustomScrollView:UIScrollView
{
id代表;
}
@属性(非原子,强)id scrollDelegate;
@结束
#导入“CustomScrollView.h”
@实现自定义滚动视图
@综合代表;
-(id)initWithFrame:(CGRect)帧
{
self=[super initWithFrame:frame];
如果(自我){
//初始化代码
}
回归自我;
}
-(id)initWithCoder:(NSCoder*)aDecoder
{
self=[super initWithCoder:aDecoder];
如果(自我)
{
}
回归自我;
}
-(BOOL)触摸应取消触控视图:(UIView*)视图
{
返回否;
}
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件
{
[self.scrollDelegate ScrollTouchesBegined:TouchwithEvent:event];
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件
{
[self.scrollDelegate ScrollTouchsMoved:TouchwithEvent:event];
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event
{
[self.scrollDelegate scrolltouchesEnded:TouchwithEvent:event];
}
-(无效)触控取消:(NSSet*)触控事件:(UIEvent*)事件
{
}
@结束
这在iPad中仍然不起作用。。。现在它根本认不出任何水龙头。但不管怎样,如果它在iPhone上工作,为什么它要停止在iPad上工作呢?因为苹果完全改变了触摸事件传递到控件的方式。你是说你已经用一个UISweepGestureRecognitor
替换了你的触摸覆盖代码,但它仍然不起作用?是的——这正是发生的情况。哪个版本的iPhone OS?我正在根据ios 4编译,并在ios 3.2上运行iPad。我不完全确定为什么会发生这种情况(我想,UIScrollView
需要处理所有的触摸),但是中的“split”解决方案帮助我解决了这个问题。