Answer the question
In order to leave comments, you need to log in
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.
If I take out the button outside this view, and I just throw it on UIScrollView, then the button runs away.
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
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question