UISearchController's UISearchBar shifts incorrectly and jumps when UITableView is scrolled











up vote
1
down vote

favorite












In the video, it's a little difficult to see what's going on, so I'll try to explain it.
https://youtu.be/yOrCJB9yZlg



I have UIViewController with UITableView inside its root view. Binded via Autolayout (there is no difference how it's binded: to SuperView or to SafeArea).



SearchBar added like this:

let search = UISearchController(searchResultsController: nil)
self.navigationItem.searchController = search



When I slowly scroll table, the transition between large navbar and compact navbar, and then animation of showing in and out of searchBar is too fast. Searchbar jumping in/out of navbar instead of smoothly opened/closed; navbar transitioning is jumping between two states, large and compact, without smoothly passes through the middle half-opened state while you slowly moving your finger on screen, like in system apps (Mail, Phone, Messages, Contacts etc).



I made the example from an empty project to demonstrate the issue; there isn't any changes to navigation bar logic, or any logic at all. Just two new VC's and this odd behaviour.



If i create xCode's "Master-Details" project example and add UISearchController to it, it will work properly. I assume its because they used UITableViewController instead of UIViewController + UITableView inside.



What the reason of this behaviour and how to fix it?










share|improve this question
























  • your question is a bit confusing. Is your problem the searching closing/opening too quickly rather than being smooth like in the system apps?
    – Manju Basha
    Nov 19 at 14:00










  • Yes, exactly. I don't know how to explain it clearly.
    – surfrider
    Nov 19 at 14:03















up vote
1
down vote

favorite












In the video, it's a little difficult to see what's going on, so I'll try to explain it.
https://youtu.be/yOrCJB9yZlg



I have UIViewController with UITableView inside its root view. Binded via Autolayout (there is no difference how it's binded: to SuperView or to SafeArea).



SearchBar added like this:

let search = UISearchController(searchResultsController: nil)
self.navigationItem.searchController = search



When I slowly scroll table, the transition between large navbar and compact navbar, and then animation of showing in and out of searchBar is too fast. Searchbar jumping in/out of navbar instead of smoothly opened/closed; navbar transitioning is jumping between two states, large and compact, without smoothly passes through the middle half-opened state while you slowly moving your finger on screen, like in system apps (Mail, Phone, Messages, Contacts etc).



I made the example from an empty project to demonstrate the issue; there isn't any changes to navigation bar logic, or any logic at all. Just two new VC's and this odd behaviour.



If i create xCode's "Master-Details" project example and add UISearchController to it, it will work properly. I assume its because they used UITableViewController instead of UIViewController + UITableView inside.



What the reason of this behaviour and how to fix it?










share|improve this question
























  • your question is a bit confusing. Is your problem the searching closing/opening too quickly rather than being smooth like in the system apps?
    – Manju Basha
    Nov 19 at 14:00










  • Yes, exactly. I don't know how to explain it clearly.
    – surfrider
    Nov 19 at 14:03













up vote
1
down vote

favorite









up vote
1
down vote

favorite











In the video, it's a little difficult to see what's going on, so I'll try to explain it.
https://youtu.be/yOrCJB9yZlg



I have UIViewController with UITableView inside its root view. Binded via Autolayout (there is no difference how it's binded: to SuperView or to SafeArea).



SearchBar added like this:

let search = UISearchController(searchResultsController: nil)
self.navigationItem.searchController = search



When I slowly scroll table, the transition between large navbar and compact navbar, and then animation of showing in and out of searchBar is too fast. Searchbar jumping in/out of navbar instead of smoothly opened/closed; navbar transitioning is jumping between two states, large and compact, without smoothly passes through the middle half-opened state while you slowly moving your finger on screen, like in system apps (Mail, Phone, Messages, Contacts etc).



I made the example from an empty project to demonstrate the issue; there isn't any changes to navigation bar logic, or any logic at all. Just two new VC's and this odd behaviour.



If i create xCode's "Master-Details" project example and add UISearchController to it, it will work properly. I assume its because they used UITableViewController instead of UIViewController + UITableView inside.



What the reason of this behaviour and how to fix it?










share|improve this question















In the video, it's a little difficult to see what's going on, so I'll try to explain it.
https://youtu.be/yOrCJB9yZlg



I have UIViewController with UITableView inside its root view. Binded via Autolayout (there is no difference how it's binded: to SuperView or to SafeArea).



SearchBar added like this:

let search = UISearchController(searchResultsController: nil)
self.navigationItem.searchController = search



When I slowly scroll table, the transition between large navbar and compact navbar, and then animation of showing in and out of searchBar is too fast. Searchbar jumping in/out of navbar instead of smoothly opened/closed; navbar transitioning is jumping between two states, large and compact, without smoothly passes through the middle half-opened state while you slowly moving your finger on screen, like in system apps (Mail, Phone, Messages, Contacts etc).



I made the example from an empty project to demonstrate the issue; there isn't any changes to navigation bar logic, or any logic at all. Just two new VC's and this odd behaviour.



If i create xCode's "Master-Details" project example and add UISearchController to it, it will work properly. I assume its because they used UITableViewController instead of UIViewController + UITableView inside.



What the reason of this behaviour and how to fix it?







ios swift uinavigationbar uisearchbar uisearchcontroller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 14:42









Damon

402317




402317










asked Nov 19 at 13:23









surfrider

757820




757820












  • your question is a bit confusing. Is your problem the searching closing/opening too quickly rather than being smooth like in the system apps?
    – Manju Basha
    Nov 19 at 14:00










  • Yes, exactly. I don't know how to explain it clearly.
    – surfrider
    Nov 19 at 14:03


















  • your question is a bit confusing. Is your problem the searching closing/opening too quickly rather than being smooth like in the system apps?
    – Manju Basha
    Nov 19 at 14:00










  • Yes, exactly. I don't know how to explain it clearly.
    – surfrider
    Nov 19 at 14:03
















your question is a bit confusing. Is your problem the searching closing/opening too quickly rather than being smooth like in the system apps?
– Manju Basha
Nov 19 at 14:00




your question is a bit confusing. Is your problem the searching closing/opening too quickly rather than being smooth like in the system apps?
– Manju Basha
Nov 19 at 14:00












Yes, exactly. I don't know how to explain it clearly.
– surfrider
Nov 19 at 14:03




Yes, exactly. I don't know how to explain it clearly.
– surfrider
Nov 19 at 14:03












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










What you have done is correct. Did you try running your code in a device? Feels more like a glitch in the simulator. I tried what you tried and it works fine for me in the device. Whereas the glitch occurs in simulator.



Refer to this article. They have explained step by step process.






share|improve this answer





















  • I can confirm that creation UITableView from code and inserting it in UIViewController solved my issue in the example. But I also had to create the UINavigationController manually from code (in AppDelegate create UIWindow, then UINavigationViewController with my ViewController as root). Otherway it didn't work. Very strange behaviour with IB. xCode's bug?
    – surfrider
    Nov 19 at 16:15












  • Thank you! By the way, a creation of all the stuff from IB is working with these settings from answer stackoverflow.com/a/50171002/667483
    – surfrider
    Nov 19 at 16:44




















up vote
1
down vote













This is a known problem and your code seems fine. This problem was already discussed here.



Problem appears when you're using UIScrollView or its subclasses with large navigation titles. It doesn't work. Problem disappears when you use UICollectionViewController or UITableViewController instead.






share|improve this answer

















  • 1




    Thanks! This thread is also very helpful. This stackoverflow.com/a/50171002/667483 solved all the problems even if using IB. I don't know which of answers is most correct, they both solved my problem in different ways. I give the vote to Manju Basha for reputation boost! :)
    – surfrider
    Nov 19 at 16:44













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',
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%2f53375589%2fuisearchcontrollers-uisearchbar-shifts-incorrectly-and-jumps-when-uitableview-i%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








up vote
1
down vote



accepted










What you have done is correct. Did you try running your code in a device? Feels more like a glitch in the simulator. I tried what you tried and it works fine for me in the device. Whereas the glitch occurs in simulator.



Refer to this article. They have explained step by step process.






share|improve this answer





















  • I can confirm that creation UITableView from code and inserting it in UIViewController solved my issue in the example. But I also had to create the UINavigationController manually from code (in AppDelegate create UIWindow, then UINavigationViewController with my ViewController as root). Otherway it didn't work. Very strange behaviour with IB. xCode's bug?
    – surfrider
    Nov 19 at 16:15












  • Thank you! By the way, a creation of all the stuff from IB is working with these settings from answer stackoverflow.com/a/50171002/667483
    – surfrider
    Nov 19 at 16:44

















up vote
1
down vote



accepted










What you have done is correct. Did you try running your code in a device? Feels more like a glitch in the simulator. I tried what you tried and it works fine for me in the device. Whereas the glitch occurs in simulator.



Refer to this article. They have explained step by step process.






share|improve this answer





















  • I can confirm that creation UITableView from code and inserting it in UIViewController solved my issue in the example. But I also had to create the UINavigationController manually from code (in AppDelegate create UIWindow, then UINavigationViewController with my ViewController as root). Otherway it didn't work. Very strange behaviour with IB. xCode's bug?
    – surfrider
    Nov 19 at 16:15












  • Thank you! By the way, a creation of all the stuff from IB is working with these settings from answer stackoverflow.com/a/50171002/667483
    – surfrider
    Nov 19 at 16:44















up vote
1
down vote



accepted







up vote
1
down vote



accepted






What you have done is correct. Did you try running your code in a device? Feels more like a glitch in the simulator. I tried what you tried and it works fine for me in the device. Whereas the glitch occurs in simulator.



Refer to this article. They have explained step by step process.






share|improve this answer












What you have done is correct. Did you try running your code in a device? Feels more like a glitch in the simulator. I tried what you tried and it works fine for me in the device. Whereas the glitch occurs in simulator.



Refer to this article. They have explained step by step process.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 15:00









Manju Basha

292319




292319












  • I can confirm that creation UITableView from code and inserting it in UIViewController solved my issue in the example. But I also had to create the UINavigationController manually from code (in AppDelegate create UIWindow, then UINavigationViewController with my ViewController as root). Otherway it didn't work. Very strange behaviour with IB. xCode's bug?
    – surfrider
    Nov 19 at 16:15












  • Thank you! By the way, a creation of all the stuff from IB is working with these settings from answer stackoverflow.com/a/50171002/667483
    – surfrider
    Nov 19 at 16:44




















  • I can confirm that creation UITableView from code and inserting it in UIViewController solved my issue in the example. But I also had to create the UINavigationController manually from code (in AppDelegate create UIWindow, then UINavigationViewController with my ViewController as root). Otherway it didn't work. Very strange behaviour with IB. xCode's bug?
    – surfrider
    Nov 19 at 16:15












  • Thank you! By the way, a creation of all the stuff from IB is working with these settings from answer stackoverflow.com/a/50171002/667483
    – surfrider
    Nov 19 at 16:44


















I can confirm that creation UITableView from code and inserting it in UIViewController solved my issue in the example. But I also had to create the UINavigationController manually from code (in AppDelegate create UIWindow, then UINavigationViewController with my ViewController as root). Otherway it didn't work. Very strange behaviour with IB. xCode's bug?
– surfrider
Nov 19 at 16:15






I can confirm that creation UITableView from code and inserting it in UIViewController solved my issue in the example. But I also had to create the UINavigationController manually from code (in AppDelegate create UIWindow, then UINavigationViewController with my ViewController as root). Otherway it didn't work. Very strange behaviour with IB. xCode's bug?
– surfrider
Nov 19 at 16:15














Thank you! By the way, a creation of all the stuff from IB is working with these settings from answer stackoverflow.com/a/50171002/667483
– surfrider
Nov 19 at 16:44






Thank you! By the way, a creation of all the stuff from IB is working with these settings from answer stackoverflow.com/a/50171002/667483
– surfrider
Nov 19 at 16:44














up vote
1
down vote













This is a known problem and your code seems fine. This problem was already discussed here.



Problem appears when you're using UIScrollView or its subclasses with large navigation titles. It doesn't work. Problem disappears when you use UICollectionViewController or UITableViewController instead.






share|improve this answer

















  • 1




    Thanks! This thread is also very helpful. This stackoverflow.com/a/50171002/667483 solved all the problems even if using IB. I don't know which of answers is most correct, they both solved my problem in different ways. I give the vote to Manju Basha for reputation boost! :)
    – surfrider
    Nov 19 at 16:44

















up vote
1
down vote













This is a known problem and your code seems fine. This problem was already discussed here.



Problem appears when you're using UIScrollView or its subclasses with large navigation titles. It doesn't work. Problem disappears when you use UICollectionViewController or UITableViewController instead.






share|improve this answer

















  • 1




    Thanks! This thread is also very helpful. This stackoverflow.com/a/50171002/667483 solved all the problems even if using IB. I don't know which of answers is most correct, they both solved my problem in different ways. I give the vote to Manju Basha for reputation boost! :)
    – surfrider
    Nov 19 at 16:44















up vote
1
down vote










up vote
1
down vote









This is a known problem and your code seems fine. This problem was already discussed here.



Problem appears when you're using UIScrollView or its subclasses with large navigation titles. It doesn't work. Problem disappears when you use UICollectionViewController or UITableViewController instead.






share|improve this answer












This is a known problem and your code seems fine. This problem was already discussed here.



Problem appears when you're using UIScrollView or its subclasses with large navigation titles. It doesn't work. Problem disappears when you use UICollectionViewController or UITableViewController instead.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 15:05









fewlinesofcode

1,846514




1,846514








  • 1




    Thanks! This thread is also very helpful. This stackoverflow.com/a/50171002/667483 solved all the problems even if using IB. I don't know which of answers is most correct, they both solved my problem in different ways. I give the vote to Manju Basha for reputation boost! :)
    – surfrider
    Nov 19 at 16:44
















  • 1




    Thanks! This thread is also very helpful. This stackoverflow.com/a/50171002/667483 solved all the problems even if using IB. I don't know which of answers is most correct, they both solved my problem in different ways. I give the vote to Manju Basha for reputation boost! :)
    – surfrider
    Nov 19 at 16:44










1




1




Thanks! This thread is also very helpful. This stackoverflow.com/a/50171002/667483 solved all the problems even if using IB. I don't know which of answers is most correct, they both solved my problem in different ways. I give the vote to Manju Basha for reputation boost! :)
– surfrider
Nov 19 at 16:44






Thanks! This thread is also very helpful. This stackoverflow.com/a/50171002/667483 solved all the problems even if using IB. I don't know which of answers is most correct, they both solved my problem in different ways. I give the vote to Manju Basha for reputation boost! :)
– surfrider
Nov 19 at 16:44




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375589%2fuisearchcontrollers-uisearchbar-shifts-incorrectly-and-jumps-when-uitableview-i%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

Wiesbaden

Marschland

Dieringhausen