Block size image when I enlarge the view












0















I have a view and within an image that works as a button. I would like to know if there is a way to lock the size of the button so that when I zoom in, the view remains small and does not enlarge with the view..



one



two










share|improve this question

























  • imageView.contentMode = .center?

    – Tamás Sengel
    Nov 20 '18 at 14:10











  • @TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted

    – user10652382
    Nov 20 '18 at 14:12











  • That's what .center (and also .left, .right etc.) does. Try it out.

    – Tamás Sengel
    Nov 20 '18 at 14:13











  • @TamásSengel no not work, I check now..

    – user10652382
    Nov 20 '18 at 14:17
















0















I have a view and within an image that works as a button. I would like to know if there is a way to lock the size of the button so that when I zoom in, the view remains small and does not enlarge with the view..



one



two










share|improve this question

























  • imageView.contentMode = .center?

    – Tamás Sengel
    Nov 20 '18 at 14:10











  • @TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted

    – user10652382
    Nov 20 '18 at 14:12











  • That's what .center (and also .left, .right etc.) does. Try it out.

    – Tamás Sengel
    Nov 20 '18 at 14:13











  • @TamásSengel no not work, I check now..

    – user10652382
    Nov 20 '18 at 14:17














0












0








0








I have a view and within an image that works as a button. I would like to know if there is a way to lock the size of the button so that when I zoom in, the view remains small and does not enlarge with the view..



one



two










share|improve this question
















I have a view and within an image that works as a button. I would like to know if there is a way to lock the size of the button so that when I zoom in, the view remains small and does not enlarge with the view..



one



two







ios swift image size






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 14:49









Scriptable

13.3k43554




13.3k43554










asked Nov 20 '18 at 14:05







user10652382




















  • imageView.contentMode = .center?

    – Tamás Sengel
    Nov 20 '18 at 14:10











  • @TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted

    – user10652382
    Nov 20 '18 at 14:12











  • That's what .center (and also .left, .right etc.) does. Try it out.

    – Tamás Sengel
    Nov 20 '18 at 14:13











  • @TamásSengel no not work, I check now..

    – user10652382
    Nov 20 '18 at 14:17



















  • imageView.contentMode = .center?

    – Tamás Sengel
    Nov 20 '18 at 14:10











  • @TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted

    – user10652382
    Nov 20 '18 at 14:12











  • That's what .center (and also .left, .right etc.) does. Try it out.

    – Tamás Sengel
    Nov 20 '18 at 14:13











  • @TamásSengel no not work, I check now..

    – user10652382
    Nov 20 '18 at 14:17

















imageView.contentMode = .center?

– Tamás Sengel
Nov 20 '18 at 14:10





imageView.contentMode = .center?

– Tamás Sengel
Nov 20 '18 at 14:10













@TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted

– user10652382
Nov 20 '18 at 14:12





@TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted

– user10652382
Nov 20 '18 at 14:12













That's what .center (and also .left, .right etc.) does. Try it out.

– Tamás Sengel
Nov 20 '18 at 14:13





That's what .center (and also .left, .right etc.) does. Try it out.

– Tamás Sengel
Nov 20 '18 at 14:13













@TamásSengel no not work, I check now..

– user10652382
Nov 20 '18 at 14:17





@TamásSengel no not work, I check now..

– user10652382
Nov 20 '18 at 14:17












2 Answers
2






active

oldest

votes


















0














I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.



The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.



    var  originalCenter : CGPoint! // The center of ButtonView in imageView.


//All functions are from the UIScrollViewDelegate.

func viewForZooming(in scrollView: UIScrollView) -> UIView?{
originalCenter = buttonView.center // remember the original position.
return imageView
}

func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
scrollView.addSubview(buttonView)//add to superView of imageImage.
}

func scrollViewDidZoom(_ scrollView: UIScrollView){
buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
}

func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
imageView.addSubview(buttonView) //put it back.
}


I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.






share|improve this answer































    0














    Because you called transform for superView. It will make all subViews inside transform together.



    You need to remake you views:



    SuperView:
    - Content view (the image view)
    - Border view
    - Button close


    When you want to zoom the image, you only need to reset the superview frame.



    You found a git SPUserResizableView.






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394785%2fblock-size-image-when-i-enlarge-the-view%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown
























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.



      The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.



          var  originalCenter : CGPoint! // The center of ButtonView in imageView.


      //All functions are from the UIScrollViewDelegate.

      func viewForZooming(in scrollView: UIScrollView) -> UIView?{
      originalCenter = buttonView.center // remember the original position.
      return imageView
      }

      func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
      buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
      scrollView.addSubview(buttonView)//add to superView of imageImage.
      }

      func scrollViewDidZoom(_ scrollView: UIScrollView){
      buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
      }

      func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
      buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
      imageView.addSubview(buttonView) //put it back.
      }


      I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.






      share|improve this answer




























        0














        I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.



        The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.



            var  originalCenter : CGPoint! // The center of ButtonView in imageView.


        //All functions are from the UIScrollViewDelegate.

        func viewForZooming(in scrollView: UIScrollView) -> UIView?{
        originalCenter = buttonView.center // remember the original position.
        return imageView
        }

        func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
        buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
        scrollView.addSubview(buttonView)//add to superView of imageImage.
        }

        func scrollViewDidZoom(_ scrollView: UIScrollView){
        buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
        }

        func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
        buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
        imageView.addSubview(buttonView) //put it back.
        }


        I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.






        share|improve this answer


























          0












          0








          0







          I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.



          The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.



              var  originalCenter : CGPoint! // The center of ButtonView in imageView.


          //All functions are from the UIScrollViewDelegate.

          func viewForZooming(in scrollView: UIScrollView) -> UIView?{
          originalCenter = buttonView.center // remember the original position.
          return imageView
          }

          func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
          buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
          scrollView.addSubview(buttonView)//add to superView of imageImage.
          }

          func scrollViewDidZoom(_ scrollView: UIScrollView){
          buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
          }

          func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
          buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
          imageView.addSubview(buttonView) //put it back.
          }


          I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.






          share|improve this answer













          I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.



          The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.



              var  originalCenter : CGPoint! // The center of ButtonView in imageView.


          //All functions are from the UIScrollViewDelegate.

          func viewForZooming(in scrollView: UIScrollView) -> UIView?{
          originalCenter = buttonView.center // remember the original position.
          return imageView
          }

          func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
          buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
          scrollView.addSubview(buttonView)//add to superView of imageImage.
          }

          func scrollViewDidZoom(_ scrollView: UIScrollView){
          buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
          }

          func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
          buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
          imageView.addSubview(buttonView) //put it back.
          }


          I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 1:09









          E.ComsE.Coms

          2,5652414




          2,5652414

























              0














              Because you called transform for superView. It will make all subViews inside transform together.



              You need to remake you views:



              SuperView:
              - Content view (the image view)
              - Border view
              - Button close


              When you want to zoom the image, you only need to reset the superview frame.



              You found a git SPUserResizableView.






              share|improve this answer






























                0














                Because you called transform for superView. It will make all subViews inside transform together.



                You need to remake you views:



                SuperView:
                - Content view (the image view)
                - Border view
                - Button close


                When you want to zoom the image, you only need to reset the superview frame.



                You found a git SPUserResizableView.






                share|improve this answer




























                  0












                  0








                  0







                  Because you called transform for superView. It will make all subViews inside transform together.



                  You need to remake you views:



                  SuperView:
                  - Content view (the image view)
                  - Border view
                  - Button close


                  When you want to zoom the image, you only need to reset the superview frame.



                  You found a git SPUserResizableView.






                  share|improve this answer















                  Because you called transform for superView. It will make all subViews inside transform together.



                  You need to remake you views:



                  SuperView:
                  - Content view (the image view)
                  - Border view
                  - Button close


                  When you want to zoom the image, you only need to reset the superview frame.



                  You found a git SPUserResizableView.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 22 '18 at 15:09









                  rmaddy

                  243k27321383




                  243k27321383










                  answered Nov 21 '18 at 4:56









                  TienLeTienLe

                  2421527




                  2421527






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394785%2fblock-size-image-when-i-enlarge-the-view%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                      Alcedinidae

                      Can an atomic nucleus contain both particles and antiparticles? [duplicate]