I've been to three of the ports and can tell you that Barcelona has a great hop-on-hop-off bus with three routes that take you all over the city. It is not expensive and you get off and walk around the areas you want to see.
Gibraltar is also great for walking around and there are taxis if you want to go up the rock to see the monkeys or caves, or alternately there are shore excursions for that.
Casablanca is hard since the ships dock quite a way out of the city and it will cost $30.00 just for a taxi to take you in to the main square and drop you off. There are lots of taxis at the pier that you can hire for a tour, but they are expensive. Find another couple to go with to cut costs. Alternately, this is one port where you might consider paying the extra for one of the ship's excursions.