C.J*_*hns 2 iphone uiscrollview ios
我正在放大滚动视图中的图像..但我的滚动视图有一个背景,我想与前景图像保持同步.
这就是我现在所拥有的.我想知道我是否必须在viewForZoomingInScrollView方法中返回bgImage ..但我只是不确定它是如何或甚至可能活跃.
这就是我在下面所做的让图像变焦..如果有人可以帮我弄清楚如何让bg同步滚动也会非常感激.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.delegate = self;
scrollView.bounces = NO;
scrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"auckland-300.jpg"]];
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"249a-134206f1d00-1342071f5d9.ImgPlayerAUCKLAND.png"]];
scrollView.contentSize = image.frame.size;
[scrollView addSubview:image];
scrollView.minimumZoomScale = 1.0;
scrollView.maximumZoomScale = 31.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
self.view = scrollView;
}
#pragma Zooming
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return image;
}
Run Code Online (Sandbox Code Playgroud)
我假设你的意思是你想让背景图像也缩放?我要做的是也使用a UIImageView作为背景图像,并将该图像和您的图像image放入容器视图中并将其返回viewForZoomingInScrollView:.所以沿着这些方向:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.delegate = self;
scrollView.bounces = NO;
backgroundImage = [[UIImageVIew alloc] initWithImage:[UIImage imageNamed:@"auckland-300.jpg"]];
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"249a-134206f1d00-1342071f5d9.ImgPlayerAUCKLAND.png"]];
// Note here you should size the container view appropriately and layout backgroundImage and image accordingly.
containerView = [[UIView alloc] initWithFrame:image.bounds];
[containerView addSubview:backgroundImage];
[containerView addSubview:image];
scrollView.contentSize = containerView.frame.size;
[scrollView addSubview:containerView];
scrollView.minimumZoomScale = 1.0;
scrollView.maximumZoomScale = 31.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
self.view = scrollView;
}
#pragma Zooming
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return containerView;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8476 次 |
| 最近记录: |