我对编程很陌生。我目前正在开发一个 iOS 应用程序,它使用 UIButtons 来访问不同的UIViews
. 每个都包含一个UIScrollView
包含一个UIImageView
。目的是拥有可缩放、可滚动和可平移的图片。我找到了一个很好的例子来说明如何做所有这些,但是代码用 @ 声明了一个图像,所以我必须创建几个UIViews
并为每个生成代码来管理特定的UIImage
(因为它们都有不同的名称)和UIScroll
. 这是不切实际的。我需要的是有一个UIViewContoller
用于不同视图的单一代码和一个处理具有不同图片的视图的代码。
这是将图像设置为滚动和缩放并将其添加到滚动视图的代码(尽管我想通过情节提要直观地包含图像,而不是通过代码)。
- (void)viewDidLoad {
[super viewDidLoad];
// Title
self.title = @"Image";
// Set up the image to scroll & zoom and add it to the scroll view
UIImage *image = [UIImage imageNamed:@"photo1.png"];
self.imageView = [[UIImageView alloc] initWithImage:image];
self.imageView.frame = (CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=image.size};
[self.scrollView addSubview:self.imageView];
请帮忙!!
谢谢你。