Despite sweeping language in the Bill of Rights, the Supreme Court has consistently ruled that nearly every right can be subjected to restrictions. Most of those restrictions must satisfy at least a few criteria though.
First of all, almost any law has to satisfy a requirement that it be written to further some legitimate state interest. The minimum is that it must serve some "rational state interest". The strictest is that it must serve some "compelling state interest", and in between those is an intermediate level, that's applied primarily to cases involving discrimination against protected classes of people. A few cases have also talked about "heightened scrutiny", and it's not 100% clear whether that's exactly the same as intermediate scrutiny or not (but at the very least, it's pretty similar).
Assuming it meets that requirement (e.g., the state shows that it's for public safety) the next point to consider is whether it's tailored narrowly to infringe on rights as little as possible while accomplishing its goal.
So for example, let's consider when cars first started to come into wide use, and some people got killed in car accidents at night. The state has a legitimate interest in preventing that danger, so some sort of motor vehicle safety law passes the first hurdle.
A law requiring headlights when driving at night probably passes the second hurdle. A law prohibiting all cars probably doesn't.
Gun control laws have a pretty easy time passing the first hurdle. The claim is nearly always going to be that it's to protect public safety, and there's little question that'll be accepted as a legitimate state interest.
The second tends to be a lot harder hurdle for gun control laws to honestly meet. Oh, don't get me wrong. Some are obvious and easy. Prohibiting arms in prisons is obvious. Prohibiting an accused gangster from carrying a machine gun into the court room where he's on trial...again, pretty easy to support.
But what people normally think of as gun control laws? A field rife with battling statistics, and little room for a court to conclude with certainty that a particular law is really infringing on rights only as much as truly needed to maintain public safety.
I suppose I should add a couple of caveats.
First of all, a court only rules on a real case, so (for example) a lot of the old "blue laws" can remain on the books almost indefinitely as long as nobody's ever charged with breaking them, even though in a lot of cases it's pretty clear that they don't serve any legitimate state interest.
Second, over time, ideas of what constitutes a "legitimate state interest" change, often dramatically. 200 years ago, quite a few courts wouldn't have even questioned the "fact" that returning slaves to their owners was obviously a legitimate state interest. I feel fairly safe guessing that most people reading this today disagree. As much as we might wish otherwise, even supreme court justices are human, and influenced by the prevailing thought of the time, no matter how bad that may look in retrospect (e.g, Dred Scott).