我目前对CATiledLayer有以下问题:当视图第一次加载时,滚动完美地工作,但是当你缩放一次时,视图捕捉到锚点(左上角),并且它不能滚动到所有。缩放的作用在于可以放大和缩小,但只能缩放到左上角。为什么我的CATiledLayer在缩放后不能在UIScrollView中滚动?
我的代码如下:
#import <QuartzCore/QuartzCore.h>
#import "PracticeViewController.h"
@implementation practiceViewController
//@synthesize image;
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"H-5" ofType:@"jpg"];
NSData *data = [NSData dataWithContentsOfFile:path];
image = [UIImage imageWithData:data];
CGRect pageRect = CGRectMake(0, 0, image.size.width, image.size.height);
CATiledLayer *tiledLayer = [CATiledLayer layer];
tiledLayer.anchorPoint = CGPointMake(0.0f, 1.0f);
tiledLayer.delegate = self;
tiledLayer.tileSize = CGSizeMake(1000, 1000);
tiledLayer.levelsOfDetail = 6;
tiledLayer.levelsOfDetailBias = 0;
tiledLayer.bounds = pageRect;
tiledLayer.transform = CATransform3DMakeScale(1.0f, -1.0f, 0.3f);
myContentView = [[UIView alloc] initWithFrame:self.view.bounds];
[myContentView.layer addSublayer:tiledLayer];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.delegate = self;
scrollView.contentSize = pageRect.size;
scrollView.minimumZoomScale = .2;
scrollView.maximumZoomScale = 1;
[scrollView addSubview:myContentView];
[self.view addSubview:scrollView];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return myContentView;
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"H-5" ofType:@"jpg"];
NSData *data = [NSData dataWithContentsOfFile:path];
image = [UIImage imageWithData:data];
CGRect imageRect = CGRectMake (0.0, 0.0, image.size.width, image.size.height);
CGContextDrawImage (ctx, imageRect, [image CGImage]);
}
@end
堆栈溢出并不打算用于进行代码审查。如果您遇到特定问题,请提出相关问题。 – 2010-05-03 22:57:46
我确实有一个具体的问题,我已经在Lucius的答案中记录下。 “好吧,我已经更新了我的代码以反映我现在的情况,现在真的只有一个问题,当视图第一次加载时,滚动效果非常好,但是当您缩放一次时,视图会捕捉到锚点(顶部它不能再滚动,缩放的作用在于它可以放大和缩小,但它只能放大到左上角。“不知道你在抱怨什么 – Brodie 2010-05-04 01:33:29
4598 - 没有真正的问题在你的问题中,解析这些评论以找出问题并不是非常简单。我编辑了你的问题,以反映你现在问的问题。 – 2010-05-04 03:33:27