That's certainly a part of it but IMO it was a lot more complex than that. IMO Brexit was the culmination of a 35 year exercise by parts of the UK press to undermine the EU - and they were enabled by politicians. Anything positive that successive governments did was claimed by those government, anything unpopular was blamed on the EU whether or not EU membership was a significant factor.
The upshot was that the UK population as a whole likely had an under-appreciation of the benefits of EU membership and an exaggerated view of the downsides (to them). The Brexiteers were sowing seed on fertile ground.
Then add in the aftereffects of the 2008 crash. It seems that a conventional response to a economic downturn is to blame recent arrivals for all society's ills. It's no coincidence that there were significant increases in support for British nationalist parties in the 1930s and 1970s when the UK economy was in recession. There may even be a 40 year cycle when the lessons of the last rise in nationalism have been forgotten.
Stick on a layer of globalisation where a lot of people have seen themselves falling behind socially and economically, especially those whose skills and abilities do not align well to the current UK economy. It's very difficult to earn a living as an unskilled or semi-skilled worker, in the past that may not have been the case.
Finally top it all off with a cherry of contrarianism. Some people (likely a small minority but in this case maybe a crucial one) simply wished to give "the establishment" a bloody nose. If you see nothing really improving in the future then maybe you are more inclined to do anything to change that future because it cannot be any worse.
The person I save the blame for is David Cameron who tried to pull a power move and hold a referendum, in order to secure his own position. There were steps he could have taken to strengthen his position like requiring a super-majority or by having the alternative to staying in the EU well defined (and disliked) but he was so confident of success, that he felt no need.