K
K
kaspartus2014-06-26 17:17:10
iOS
kaspartus, 2014-06-26 17:17:10

UIScrollView: how to stack text/buttons while maintaining their size and position?

Purpose:
There is a picture, with all sorts of signatures, buttons and other things. I want that when the image is zoomed in/out, the dimensions of the auxiliary elements are preserved, while they remain in place.
Problem:
I implemented zooming through UIScrollView, put a separate UIView on it, on which lies UIImageView and UIButton.
I connect a delegate for UIScrollView, in the delegate method viewForZoomingInScrollView I give that very separate view. Bottom line: the picture of the button is also zoomed, but remains in place.
b100f72763bd4fbdb320e3cbc12f698e.gif
If I take out the button outside this view, and I just throw it on UIScrollView, then the button runs away.
fa656536981f4b139c30d1b805862789.gif
The code for this is not written that much:

#import "SVTViewController.h"

@interface SVTViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation SVTViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
  self.scrollView.minimumZoomScale = 1;
  self.scrollView.maximumZoomScale = 20.0;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

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

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
  
}

@end

I will leave a link to the git with a test project:
https://github.com/AlloyDev/UIScrollViewSubviewsSc...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kaspartus, 2014-06-27
@kaspartus

As a result, I won by modifying the option where the buttons lie on the contentView and are scaled along with the picture itself (1 GIF).
I picked it up through the delegate method -(void)scrollViewDidZoom:(UIScrollView *)scrollView
There I do the transformation:
I thought that it would lag, I checked it on 100 buttons - everything works perfectly on the third board.
ps updated turnip

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question