- 能干嘛?
你想显示一个大图层里面的一小部分,如:查看大图片,查看一大段数据或者长文本。 - 拿啥来干?
- (void)scrollPoint:(CGPoint)p;
- 局限
能像scrollView滚动视图,但并不能有滚动条以及有明确的滚动范围以及其他scrollView的效果( 可能滑动过程中,让视图整体滑出视野)
- 代码示例
view继承的类:
@implementation shapeView
+ (Class)layerClass {
return [CAScrollLayer class];
}
- (void)setUp {
self.layer.masksToBounds = YES;
UIPanGestureRecognizer *recognizer = nil;
recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self addGestureRecognizer:recognizer];
}
- (id)initWithFrame:(CGRect)frame {
if((self = [super initWithFrame:frame])) {
[self setUp];
}
return self;
}
- (void)awakeFromNib {
[self setUp];
}
- (void)pan:(UIPanGestureRecognizer *)recognizer {
CGPoint offset = self.bounds.origin;
offset.x -= [recognizer translationInView:self].x;
offset.y -= [recognizer translationInView:self].y;
[(CAScrollLayer *)self.layer scrollToPoint:offset];
[recognizer setTranslation:CGPointZero inView:self];
}
@end
viewController:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"00000"];
UIImageView *iv = [[UIImageView alloc] initWithImage:image];
[self.clipView addSubview:iv];
}
效果图: