By default, you must have a completely free hand to cast a spell that has somatic components but does not have material components. That free hand may not even be holding a spellcasting focus.
A common way to avoid this problem is to take the War CasterWar Caster feat (PHB, p. 170). The second bullet of the feat reads (emphasis mine):
- You can perform the somatic components of spells even when you have weapons or a shield in one or both hands.
This will allow you to, say, cast shield (which requires only somatic components) while wielding a longsword in one hand and a shield in the other.
Using the War Caster feat, could a Hexblade warlock still cast shield if they were holding a +1 rod of the pact keeper in one hand and a wand of lightning bolts in the other? Does the answer change if you use the rod as an improvised weapon? Can a forest gnome wizard with War Caster and a wand in one hand really cast more spells by holding the barbarian's greataxe in the other hand rather than another wand?