views:

699

answers:

2

hey guys, this is my first time post here, and im pretty new to iphone programming. i just started about a month ago and have only been tinkering with small tutorial type applications but anyways, heres my question

i currently have a UIScrollView thats scrollable and zoomable, that loads a UIImageView subview, and i want to add in some controls(UIButtons) over the image view but when i zoom in and out the whole group(the buttons and the image) zoom togeather.

if i add the UIButtons to my UIScrollView and zoom, the image zooms and the buttons stay in origional place

if i add the UIButtons to my UIImageView they zoom correctly but arent buttons anymore. IE they lose their interactivity.

later ill add lots of buttons into an array and add them.

i would appreciate any help i can get

this is part of my 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];

}

A: 

Hi,

This might not help and it is not what it appears that you want to do.

However, when I want buttons associated with a scrollview, I add a parent view, add the buttons to that view and also add the scrollview to that view. The button(s) and the scrollview would be siblings. This allows the user to scroll around the contents of the scrollview, while insuring that the buttons are always in view.

-isdi-

ISDi
A: 

By default, UIImageView has userInteraction disabled. Have you changed this?

Also, I would be really uneasy adding subviews to an UIImageView, it's really meant to hold one image. It would be better to create a normal UIView and add the UIButtons and UIImageView to that. It's very easy to control the ordering so that the buttons appears on top of the image.

P.S. Just to make your life easier, instead of :

[scrollView2 setContentSize:CGSizeMake(scroll2ImageView.frame.size.width, scroll2ImageView.frame.size.height)];

You can use :

[scrollView2 setContentSize:scroll2ImageView.frame.size];
David Kanarek