UIImageView and UIScrollView zooming

后端 未结 6 1652
抹茶落季
抹茶落季 2020-12-04 19:45

Do I actually need a UIPinchGestureRecognizer inside a UIScrollView to have the pinch working? If yes how do I do it? I am trying to implement what flipboard has, where it b

6条回答
  •  悲哀的现实
    2020-12-04 20:28

    I guess this answer may be unnecessary but I have had similar problems as @adit and solved it in a very simple way (I think) and maybe someone with similar challenges can use it:

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        self.view.backgroundColor = [UIColor yellowColor];
    
        UIImage *imageToLoad = [UIImage imageNamed:@"background_green"];
    
        self.myImageView = [[UIImageView alloc]initWithImage:imageToLoad];
        self.myScrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
        [self.myScrollView addSubview:self.myImageView];
        self.myScrollView.contentSize = self.myImageView.bounds.size;
        self.myScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
        self.myScrollView.minimumZoomScale = 0.3f;
        self.myScrollView.maximumZoomScale = 3.0f;
        self.myScrollView.delegate = self;
        [self.view addSubview:self.myScrollView];
    }
    
    - (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView {
        NSLog(@"viewForZoomingInScrollView");
        return self.myImageView;
    } 
    

    My problem was a very simple I had forgot to add self.myScrollView.delegate = self;, which was the reason why i had problems. It took me forever to figure that simple problem out, i guess I did not see the forrest for all the trees :-)

提交回复
热议问题