Scroll UICollectionViewCell Swift 3 acording to the selected UITextField

Multi tool use
Multi tool use












0















I created a storyboard with a toolbar. Also, I created a UICollectionViewCell/XIB and imported it inside the storyboard. I added many UITextFields inside the UICollectionViewCell. When
I select the UITextFields which are in the bottom of the screen, the screen doesn’t scroll to show it. Could you give me some tip about how to solve that?










share|improve this question



























    0















    I created a storyboard with a toolbar. Also, I created a UICollectionViewCell/XIB and imported it inside the storyboard. I added many UITextFields inside the UICollectionViewCell. When
    I select the UITextFields which are in the bottom of the screen, the screen doesn’t scroll to show it. Could you give me some tip about how to solve that?










    share|improve this question

























      0












      0








      0








      I created a storyboard with a toolbar. Also, I created a UICollectionViewCell/XIB and imported it inside the storyboard. I added many UITextFields inside the UICollectionViewCell. When
      I select the UITextFields which are in the bottom of the screen, the screen doesn’t scroll to show it. Could you give me some tip about how to solve that?










      share|improve this question














      I created a storyboard with a toolbar. Also, I created a UICollectionViewCell/XIB and imported it inside the storyboard. I added many UITextFields inside the UICollectionViewCell. When
      I select the UITextFields which are in the bottom of the screen, the screen doesn’t scroll to show it. Could you give me some tip about how to solve that?







      ios swift scroll xib






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 29 '18 at 21:16









      MarcelMarcel

      1411113




      1411113
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Is your cell height dynamic or fixed? If it is fixed, you can have a trick like, once the textfield becomes active, detect the selected cell with some delegate or didSelectItemAt, then multiply the indexPath.row of the cell with cellHeight property, then set contentOffset of collectionView to that value like:



          // cellHeight property is something you should have declared somewhere.
          collectionView.setContentOffset(CGPoint(x: 0.0, y: cellHeight * indexPath.row), animated: true)


          If the solution above does not work, then get the keyboardHeight programmatically, or set a value that would be good enough for you to scroll up, for example I will set it to 200, then get the currentOffset, add your value to currentOffset's y value in didSelectItemAt method, (just for reference):



          let currentOffSet = collectionView.contentOffset
          let newOffset = CGPoint(x: 0.0, y: currentOffSet.y + 200.0)
          collectionView.setContentOffset(newOffset, animated: true)


          This might be a better solution depending on your application. But remember to set offSet back to original value, maybe in resignFirstResponder kind of method with your textField, so there wont be a weird behaviour each time user taps a cell.






          share|improve this answer


























          • hi emrepun. how could I know if the cell height is fixed or dynamic?

            – Marcel
            Dec 30 '18 at 14:42













          • You should know that actually, how did you design your cells? Did you give fix heights on storyboard, or in sizeForItemAt method programmatically? Or is it dynamic and calculates automatically?

            – emrepun
            Dec 30 '18 at 15:30











          • I added a toolbar on the screen. Below, I added the collectionview on the full screen. The collectionview contains an imageview and three textfields one below the other. There are some textviews too

            – Marcel
            Dec 30 '18 at 17:03











          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%2f53973393%2fscroll-uicollectionviewcell-swift-3-acording-to-the-selected-uitextfield%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Is your cell height dynamic or fixed? If it is fixed, you can have a trick like, once the textfield becomes active, detect the selected cell with some delegate or didSelectItemAt, then multiply the indexPath.row of the cell with cellHeight property, then set contentOffset of collectionView to that value like:



          // cellHeight property is something you should have declared somewhere.
          collectionView.setContentOffset(CGPoint(x: 0.0, y: cellHeight * indexPath.row), animated: true)


          If the solution above does not work, then get the keyboardHeight programmatically, or set a value that would be good enough for you to scroll up, for example I will set it to 200, then get the currentOffset, add your value to currentOffset's y value in didSelectItemAt method, (just for reference):



          let currentOffSet = collectionView.contentOffset
          let newOffset = CGPoint(x: 0.0, y: currentOffSet.y + 200.0)
          collectionView.setContentOffset(newOffset, animated: true)


          This might be a better solution depending on your application. But remember to set offSet back to original value, maybe in resignFirstResponder kind of method with your textField, so there wont be a weird behaviour each time user taps a cell.






          share|improve this answer


























          • hi emrepun. how could I know if the cell height is fixed or dynamic?

            – Marcel
            Dec 30 '18 at 14:42













          • You should know that actually, how did you design your cells? Did you give fix heights on storyboard, or in sizeForItemAt method programmatically? Or is it dynamic and calculates automatically?

            – emrepun
            Dec 30 '18 at 15:30











          • I added a toolbar on the screen. Below, I added the collectionview on the full screen. The collectionview contains an imageview and three textfields one below the other. There are some textviews too

            – Marcel
            Dec 30 '18 at 17:03
















          0














          Is your cell height dynamic or fixed? If it is fixed, you can have a trick like, once the textfield becomes active, detect the selected cell with some delegate or didSelectItemAt, then multiply the indexPath.row of the cell with cellHeight property, then set contentOffset of collectionView to that value like:



          // cellHeight property is something you should have declared somewhere.
          collectionView.setContentOffset(CGPoint(x: 0.0, y: cellHeight * indexPath.row), animated: true)


          If the solution above does not work, then get the keyboardHeight programmatically, or set a value that would be good enough for you to scroll up, for example I will set it to 200, then get the currentOffset, add your value to currentOffset's y value in didSelectItemAt method, (just for reference):



          let currentOffSet = collectionView.contentOffset
          let newOffset = CGPoint(x: 0.0, y: currentOffSet.y + 200.0)
          collectionView.setContentOffset(newOffset, animated: true)


          This might be a better solution depending on your application. But remember to set offSet back to original value, maybe in resignFirstResponder kind of method with your textField, so there wont be a weird behaviour each time user taps a cell.






          share|improve this answer


























          • hi emrepun. how could I know if the cell height is fixed or dynamic?

            – Marcel
            Dec 30 '18 at 14:42













          • You should know that actually, how did you design your cells? Did you give fix heights on storyboard, or in sizeForItemAt method programmatically? Or is it dynamic and calculates automatically?

            – emrepun
            Dec 30 '18 at 15:30











          • I added a toolbar on the screen. Below, I added the collectionview on the full screen. The collectionview contains an imageview and three textfields one below the other. There are some textviews too

            – Marcel
            Dec 30 '18 at 17:03














          0












          0








          0







          Is your cell height dynamic or fixed? If it is fixed, you can have a trick like, once the textfield becomes active, detect the selected cell with some delegate or didSelectItemAt, then multiply the indexPath.row of the cell with cellHeight property, then set contentOffset of collectionView to that value like:



          // cellHeight property is something you should have declared somewhere.
          collectionView.setContentOffset(CGPoint(x: 0.0, y: cellHeight * indexPath.row), animated: true)


          If the solution above does not work, then get the keyboardHeight programmatically, or set a value that would be good enough for you to scroll up, for example I will set it to 200, then get the currentOffset, add your value to currentOffset's y value in didSelectItemAt method, (just for reference):



          let currentOffSet = collectionView.contentOffset
          let newOffset = CGPoint(x: 0.0, y: currentOffSet.y + 200.0)
          collectionView.setContentOffset(newOffset, animated: true)


          This might be a better solution depending on your application. But remember to set offSet back to original value, maybe in resignFirstResponder kind of method with your textField, so there wont be a weird behaviour each time user taps a cell.






          share|improve this answer















          Is your cell height dynamic or fixed? If it is fixed, you can have a trick like, once the textfield becomes active, detect the selected cell with some delegate or didSelectItemAt, then multiply the indexPath.row of the cell with cellHeight property, then set contentOffset of collectionView to that value like:



          // cellHeight property is something you should have declared somewhere.
          collectionView.setContentOffset(CGPoint(x: 0.0, y: cellHeight * indexPath.row), animated: true)


          If the solution above does not work, then get the keyboardHeight programmatically, or set a value that would be good enough for you to scroll up, for example I will set it to 200, then get the currentOffset, add your value to currentOffset's y value in didSelectItemAt method, (just for reference):



          let currentOffSet = collectionView.contentOffset
          let newOffset = CGPoint(x: 0.0, y: currentOffSet.y + 200.0)
          collectionView.setContentOffset(newOffset, animated: true)


          This might be a better solution depending on your application. But remember to set offSet back to original value, maybe in resignFirstResponder kind of method with your textField, so there wont be a weird behaviour each time user taps a cell.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 30 '18 at 0:04

























          answered Dec 29 '18 at 23:49









          emrepunemrepun

          1,3451417




          1,3451417













          • hi emrepun. how could I know if the cell height is fixed or dynamic?

            – Marcel
            Dec 30 '18 at 14:42













          • You should know that actually, how did you design your cells? Did you give fix heights on storyboard, or in sizeForItemAt method programmatically? Or is it dynamic and calculates automatically?

            – emrepun
            Dec 30 '18 at 15:30











          • I added a toolbar on the screen. Below, I added the collectionview on the full screen. The collectionview contains an imageview and three textfields one below the other. There are some textviews too

            – Marcel
            Dec 30 '18 at 17:03



















          • hi emrepun. how could I know if the cell height is fixed or dynamic?

            – Marcel
            Dec 30 '18 at 14:42













          • You should know that actually, how did you design your cells? Did you give fix heights on storyboard, or in sizeForItemAt method programmatically? Or is it dynamic and calculates automatically?

            – emrepun
            Dec 30 '18 at 15:30











          • I added a toolbar on the screen. Below, I added the collectionview on the full screen. The collectionview contains an imageview and three textfields one below the other. There are some textviews too

            – Marcel
            Dec 30 '18 at 17:03

















          hi emrepun. how could I know if the cell height is fixed or dynamic?

          – Marcel
          Dec 30 '18 at 14:42







          hi emrepun. how could I know if the cell height is fixed or dynamic?

          – Marcel
          Dec 30 '18 at 14:42















          You should know that actually, how did you design your cells? Did you give fix heights on storyboard, or in sizeForItemAt method programmatically? Or is it dynamic and calculates automatically?

          – emrepun
          Dec 30 '18 at 15:30





          You should know that actually, how did you design your cells? Did you give fix heights on storyboard, or in sizeForItemAt method programmatically? Or is it dynamic and calculates automatically?

          – emrepun
          Dec 30 '18 at 15:30













          I added a toolbar on the screen. Below, I added the collectionview on the full screen. The collectionview contains an imageview and three textfields one below the other. There are some textviews too

          – Marcel
          Dec 30 '18 at 17:03





          I added a toolbar on the screen. Below, I added the collectionview on the full screen. The collectionview contains an imageview and three textfields one below the other. There are some textviews too

          – Marcel
          Dec 30 '18 at 17:03


















          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%2f53973393%2fscroll-uicollectionviewcell-swift-3-acording-to-the-selected-uitextfield%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







          HTVWnoZAIjvNzSgCyWC,iFH,V,OsVe,Xp
          80kpZrfUbFloOlSNWIlAhrN Ii338Z,o8 qA

          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas