UIButtons over UIImageView Scaling

Hi guys, this is my first post here, and I'm pretty new to programming on iphone. I just started about a month ago and only dealt with small training types of applications, but anyway, my question

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

if I add UIButtons to my UIScrollView and zoom in, the image scaling and buttons stay in their original place

if I add UIButtons to my UIImageView, they will scale correctly and the buttons arent bigger. IE they lose their interactivity.

later add a lot of elements to the 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];

}

+3
source share
3 answers

This may not help, and it is not that it seems that you want to do it.

, , scrollview, , , scrollview . () scrollview . , , .

-isdi -

0

UIImageView . ?

, subviews UIImageView, . UIView UIButtons UIImageView. , .

P.S. , :

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

:

[scrollView2 setContentSize:scroll2ImageView.frame.size];
0

, (, ), contentView. , , contentView, imageView ..

UIScrollView : ( scrollView, )

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.contentView;
}

, , , .

scrollView contentSize .

0

Source: https://habr.com/ru/post/1720317/


All Articles