This paper presents a novel nonlinear control strategy tailored for foldable quadrotors capable of altering their morphology in-flight. By changing the quadrotor's shape through servo motors, these adaptive systems can effectively overcome various challenges, including diverse environmental conditions, such as obstacles and climate variations. The proposed control approach utilizes a double-loop control method to enhance the robustness and performance of the folding quadrotor during flight. The outer loop consists of a nonlinear PID controller responsible for regulating motion in the X and Y directions, while the inner loop features a sliding mode controller for altitude control in the Z direction and attitude stabilization. This dual-loop structure ensures the quadrotor's stability even during arm folding. The firefly algorithm is employed to optimize the parameters of both controllers, minimizing position errors using the Root Mean Square Error (RMSE) as a performance metric. Our results demonstrate a significant improvement in the quadrotor's performance and adaptability to various proposed morphologies, with error rates reduced to near-negligible levels for all shapes. Specifically, the X position error was reduced by 100% for all morphologies, the Y position error by 95% for the X shape, 97% for the T shape, 98% for the H shape, and 99% for the O shape, and the Z position error by 99% for all morphologies.