If I sell my iPhone, how will the warranty be affected?
The original warranty usually the standard 1 year + any AppleCare stays with the iPhone. And any remaining warranty transfers to the new owners.
Apple Care FAQs

Is the AppleCare Protection Plan transferable?
Yes. If you choose to sell or give away your Apple product, you can also transfer the ownership of the AppleCare Protection Plan. Please see the AppleCare Protection Plan Terms and Conditions for complete details.