我对iphone编程很陌生。我大约一个月前才开始,只在修补小型教程类型的应用程序,但无论如何,这是我的问题。
我目前有一个可滚动和可缩放的 UIScrollView,它加载一个 UIImageView 子视图,我想在图像视图上添加一些控件(UIButtons)但是当我放大和缩小整个组(按钮和图像)时,一起缩放.
如果我将 UIButtons 添加到我的 UIScrollView 并缩放,则图像会缩放并且按钮会留在原始位置
如果我将 UIButtons 添加到我的 UIImageView 中,它们会正确缩放,但不再是按钮。即他们失去了交互性。
后来生病将许多按钮添加到数组中并添加它们。
我会很感激我能得到的任何帮助
这是我的 mainViewController.m 的一部分:
- (void)viewDidLoad
{
[scrollView2 setBackgroundColor:[UIColor blackColor]];
[scrollView2 setCanCancelContentTouches:NO];
scrollView2.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView2.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scroll2ImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bigNH.jpg"]];
[scrollView2 addSubview:scroll2ImageView];
[scrollView2 setContentSize:CGSizeMake(scroll2ImageView.frame.size.width, scroll2ImageView.frame.size.height)];
scrollView2.minimumZoomScale = .5;
scrollView2.maximumZoomScale = 3;
scrollView2.delegate = self;
[scrollView2 setScrollEnabled:YES];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect newSize = CGRectMake(658, 435, 50, 50); // position in the parent view and set the size of the button
myButton.frame = newSize;
[myButton setImage:[UIImage imageNamed:@"redStop.png"] forState:UIControlStateNormal];
// add targets and actions
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
[scroll2ImageView addSubview:myButton];
[redLineArray addObject:myButton];
[scroll2ImageView release];
}