Recently, Unmanned Aerial Vehicles (UAVs) have been integrated into Mobile Edge Computing (MEC) systems to handle substantial data tasks from distributed user devices, thereby reducing computational task latency and energy consumption, and enhancing quality of service. However, existing UAV-assisted MEC systems face challenges such as limited computational capabilities and energy resources, inefficient task allocation, and suboptimal UAV trajectories, which increase latency and energy consumption. To effectively confront these challenges, this paper proposes a novel approach that reduces the system's average latency and enhances energy efficiency through a joint optimization of user association, task allocation, and UAV dynamic trajectories. First, we develop a comprehensive joint optimization framework that integrates user association, task allocation, and UAV trajectory planning to minimize latency and energy consumption. Second, we formulate the problem as a Markov Decision Process (MDP) and apply the Twin Delayed Deep Deterministic Policy Gradient algorithm in Deep Reinforcement Learning to solve the MDP, leveraging the high continuity in the state and action spaces of the system. Finally, simulation results demonstrate that our proposed approach outperforms existing baseline algorithms in reducing the system's average delay and improving energy efficiency.