Move frame adjustment into a separate method.
Added missing break.
Don't overwrite the same local variable for different purposes.
Center popover horizontally in parent view if it nearly fills its width.