├── .gitignore ├── LICENSE ├── README.md ├── Resources ├── demo_h.gif └── demo_v.gif └── VideoTransitionDemo ├── VideoTransitionDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── VideoTransitionDemo ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── navigation_back.imageset │ │ ├── Contents.json │ │ └── navigation_back.pdf │ ├── video_full.imageset │ │ ├── Contents.json │ │ └── video_full.pdf │ └── video_small.imageset │ │ ├── Contents.json │ │ └── video_small.pdf ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── CommentInputViewController.swift ├── DetailViewController.swift ├── Extension │ ├── CAMediaTimingFunction+Extension.swift │ └── UIView+Extension.swift ├── HorizontalFullViewController.swift ├── Info.plist ├── Transition │ ├── Transition.swift │ ├── VideoDetailTransition.swift │ └── VideoFullTransition.swift ├── Utils │ ├── Auto.swift │ ├── Inch.swift │ └── StoryBoard.swift ├── VerticalFullViewController.swift ├── View │ ├── PlayerView.swift │ ├── VideoCommentTableViewCell.swift │ └── VideoTableViewCell.swift └── ViewController.swift ├── VideoTransitionDemoTests ├── Info.plist └── VideoTransitionDemoTests.swift └── VideoTransitionDemoUITests ├── Info.plist └── VideoTransitionDemoUITests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VideoTransitionDemo - 视频过渡效果演示 2 | 3 | 4 | ### 前言 5 | 6 | 应项目需求, 实现视频播放并支持从列表到全屏到详情的流程过渡, 并在过渡中保持视频播放状态, 同时横屏视频模式下, 全屏或详情页面时旋转可以自动切换, 返回时顺序跳转. 7 | Demo中完美还原以上需求, 实现方式具有一定参考价值, 但并不一定适用于其他需求, 仅供参考. 8 | 9 | ### 预览 10 | 11 | ![竖屏](https://github.com/lixiang1994/VideoTransitionDemo/blob/master/Resources/demo_v.gif) 12 | ![横屏](https://github.com/lixiang1994/VideoTransitionDemo/blob/master/Resources/demo_h.gif) 13 | 14 | ### 概述 15 | 16 | 通过`UIViewController`的`present/dismiss`进行从视频列表到全屏或者详情页的跳转. 17 | 18 | 通过自定义`present/dismiss`动画实现过渡效果. 19 | 20 | 总共分为4个页面: 21 | - 视频列表页面 22 | - 视频竖屏全屏页面 23 | - 视频横屏全屏页面 24 | - 视频详情页面 (带评论列表的那种) 25 | 26 | 跳转分为两种流程: 27 | - 列表 -> 全屏 -> 详情 28 | - 列表 -> 详情 -> 全屏 29 | 30 | 动画效果均为从原有页面视频位置过渡到目标页面视频位置. 31 | 32 | 播放器使用的是`AVPlayer`, 通过`AVPlayerLayer`展示视频画面, 全局只有一个播放器和一个对应的`AVPlayerLayer`, 过渡中通过切换`AVPlayerLayer`的所属视图完成效果. 33 | 34 | 支持`AVPlayerLayer`的`AVLayerVideoGravity`属性切换不同模式的动画效果. 35 | 36 | 对过渡处理做了简单封装, 以保证未来需求变动增加新页面跳转时可以快速适配. 37 | 38 | ### 问题记录 39 | 40 | #### Q: 横竖屏切换 原有页面显示异常 41 | #### A: 42 | 43 | 在原有页面的`viewWillAppear(_:)`中重新设置`view`的`frame` 44 | ``` 45 | override func viewWillAppear(_ animated: Bool) { 46 | super.viewWillAppear(animated) 47 | // 解决横竖屏切换时 view异常 48 | view.frame = UIScreen.main.bounds 49 | } 50 | ``` 51 | 52 | #### Q: 动画中 `AVPlayerLayer` 无法和`View`的效果同步 53 | #### A: 54 | 重写`UIView`的`layoutSubviews()`方法 获取`bounds.size`的动画对象, 通过`CATransaction`重新设置`Layer`的`frame`属性与`View`的`bounds`同步. 55 | ``` 56 | override func layoutSubviews() { 57 | super.layoutSubviews() 58 | 59 | if let animation = layer.animation(forKey: "bounds.size") { 60 | CATransaction.begin() 61 | CATransaction.setAnimationDuration(animation.duration) 62 | CATransaction.setAnimationTimingFunction(animation.timingFunction) 63 | layer.sublayers?.forEach({ $0.frame = bounds }) 64 | CATransaction.commit() 65 | } else { 66 | layer.sublayers?.forEach({ $0.frame = bounds }) 67 | } 68 | } 69 | ``` 70 | 71 | #### Q: 切换`AVPlayerLayer`的`videoGravity`属性时 如何与过渡动画一致? 72 | #### A: 73 | 在过渡的动画块中使用`CATransaction`为`videoGravity`赋值. 74 | ``` 75 | CATransaction.begin() 76 | CATransaction.setAnimationDuration(duration) 77 | CATransaction.setAnimationTimingFunction(.easeInOut) 78 | playerLayer.videoGravity = self.targetGravity 79 | CATransaction.commit() 80 | ``` 81 | 82 | #### Q: 自定义`present`跳转横屏页面时为何返回后原页面也变成了横屏 83 | #### A: 84 | 目标页面的`modalPresentationStyle`属性要使用`.fullScreen`, 不要使用`.custom` 85 | ``` 86 | controller.modalPresentationStyle = .fullScreen 87 | ``` 88 | 89 | #### Q: 跳转横屏页面时 原有页面出现布局效果异常的情况 90 | #### A: 91 | 如果使用`AutoLayout`布局, 跳转横屏页面时 `SafeArea`会发生变化, 这会影响到原竖屏页面的布局, 所以这里视频页面布局时不建议使用`SafeArea`, Demo中我使用了[Inch](https://github.com/lixiang1994/Inch)工具来解决适配细节. 92 | 93 | ### 总结 94 | 95 | 视频跳转全屏的实现千千万, 但每种方案都有利有弊, 举个例子. 96 | 97 | 常见的`UIView`直接添加到当前`UIWindow`上然后做视图动画来达到全屏效果, 优点: 方便快捷 实现简单, 缺点: `statusBar`以及全面屏设备的底部横线"`Home`"还处于竖屏状态 并且还要同步处理系统音量视图的旋转等等, 改动范围比较杂, 有些得不偿失的感觉. 98 | 99 | 还有一种是在原页面中操作视频视图做过渡动画, 动画结束后再通过无动画的`present`切换到目标页面, 这种方法较前者的优点在于利用了`UIViewController`的一些特性, 同时也解决了`statusBar`方向等问题, 但是缺点也是有的, 对应原页面的依赖和影响过于强烈, 因为要在原页面中处理动画等. 100 | 101 | 最后说说看为何我会选择自定义`present`动画的这种方案, 首先 要说一句真理: 在Apple的平台上搞事情 最好还是按照Apple推荐的方式来做比较稳妥, 不然坑并不会比Apple挖的少, 可以玩骚操作, 但是要能承担得起所带来的问题或者说要负担的起某些责任吧, 说个真实的案例, 也算是一种常见的现象, 很多同类猿 很喜欢探索新的技术, 但是每次都在项目中尝试新技术, 可能是某些大佬的开源框架, 也可能是某些很巧妙的思路或者方案, 但是尝试归尝试, 不要弄得项目中各种技术泛滥, 各种听都没听过的第三方 (可能我见识少 某些几个Star的或者几年不更新的库 确实了解不多), 对于拿公司项目做练手跳板的人 我是真的很鄙视, 自私的无法形容, 根本没有考虑过后来人的感受和对于团队的维护成本, 写个Demo尝试锻炼一下不会死的. 102 | 103 | 😔 言归正传, 扯远了, 充分利用`UIViewController`的特性并且将处理代码进行封装, 方便后续适配新页面跳转, 不牵扯其他地方的改动, 仅仅是页面跳转而已, 维护成本相对较低. 104 | 105 | 106 | ### 如果你有更好的想法 欢迎Issues留言讨论, 我是LEE, 再见. 107 | -------------------------------------------------------------------------------- /Resources/demo_h.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lixiang1994/VideoTransitionDemo/60a2d0dafb6c04736f67db6a58c56cc8d09962a4/Resources/demo_h.gif -------------------------------------------------------------------------------- /Resources/demo_v.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lixiang1994/VideoTransitionDemo/60a2d0dafb6c04736f67db6a58c56cc8d09962a4/Resources/demo_v.gif -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C92451A02297A20A005EC0FA /* Inch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924519E2297A20A005EC0FA /* Inch.swift */; }; 11 | C92451A12297A20A005EC0FA /* Auto.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924519F2297A20A005EC0FA /* Auto.swift */; }; 12 | C92EC33220BBAF4500B26F00 /* CommentInputViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92EC33120BBAF4500B26F00 /* CommentInputViewController.swift */; }; 13 | C9498EC120AE651200C12574 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9498EC020AE651200C12574 /* AppDelegate.swift */; }; 14 | C9498EC320AE651200C12574 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9498EC220AE651200C12574 /* ViewController.swift */; }; 15 | C9498EC620AE651200C12574 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9498EC420AE651200C12574 /* Main.storyboard */; }; 16 | C9498EC820AE651300C12574 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9498EC720AE651300C12574 /* Assets.xcassets */; }; 17 | C9498ECB20AE651300C12574 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9498EC920AE651300C12574 /* LaunchScreen.storyboard */; }; 18 | C9498EEF20AE681100C12574 /* HorizontalFullViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9498EEE20AE681100C12574 /* HorizontalFullViewController.swift */; }; 19 | C9498EF120AE682500C12574 /* VerticalFullViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9498EF020AE682500C12574 /* VerticalFullViewController.swift */; }; 20 | C9498EF320AE683700C12574 /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9498EF220AE683700C12574 /* DetailViewController.swift */; }; 21 | C9498EF520AE694700C12574 /* VideoTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9498EF420AE694700C12574 /* VideoTableViewCell.swift */; }; 22 | C9498EF720AE6C0F00C12574 /* StoryBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9498EF620AE6C0F00C12574 /* StoryBoard.swift */; }; 23 | C9ABF09120AE71E600061EDF /* VideoFullTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ABF09020AE71E600061EDF /* VideoFullTransition.swift */; }; 24 | C9ABF09320AE72C900061EDF /* Transition.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ABF09220AE72C800061EDF /* Transition.swift */; }; 25 | C9ABF09520AE8AF900061EDF /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ABF09420AE8AF900061EDF /* UIView+Extension.swift */; }; 26 | C9ABF09720AEB06F00061EDF /* VideoDetailTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ABF09620AEB06F00061EDF /* VideoDetailTransition.swift */; }; 27 | C9ABF09920AECB7A00061EDF /* PlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ABF09820AECB7A00061EDF /* PlayerView.swift */; }; 28 | C9E38DE420B40AB3000A3B5B /* CAMediaTimingFunction+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E38DE320B40AB3000A3B5B /* CAMediaTimingFunction+Extension.swift */; }; 29 | C9E38DE920B412A6000A3B5B /* VideoCommentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E38DE820B412A6000A3B5B /* VideoCommentTableViewCell.swift */; }; 30 | /* End PBXBuildFile section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | C924519E2297A20A005EC0FA /* Inch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Inch.swift; sourceTree = ""; }; 34 | C924519F2297A20A005EC0FA /* Auto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Auto.swift; sourceTree = ""; }; 35 | C92EC33120BBAF4500B26F00 /* CommentInputViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommentInputViewController.swift; sourceTree = ""; }; 36 | C9498EBD20AE651200C12574 /* VideoTransitionDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VideoTransitionDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | C9498EC020AE651200C12574 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 38 | C9498EC220AE651200C12574 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 39 | C9498EC520AE651200C12574 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 40 | C9498EC720AE651300C12574 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 41 | C9498ECA20AE651300C12574 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 42 | C9498ECC20AE651300C12574 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | C9498ED520AE651300C12574 /* VideoTransitionDemoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoTransitionDemoTests.swift; sourceTree = ""; }; 44 | C9498ED720AE651300C12574 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | C9498EE020AE651300C12574 /* VideoTransitionDemoUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoTransitionDemoUITests.swift; sourceTree = ""; }; 46 | C9498EE220AE651300C12574 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 47 | C9498EEE20AE681100C12574 /* HorizontalFullViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HorizontalFullViewController.swift; sourceTree = ""; }; 48 | C9498EF020AE682500C12574 /* VerticalFullViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerticalFullViewController.swift; sourceTree = ""; }; 49 | C9498EF220AE683700C12574 /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = ""; }; 50 | C9498EF420AE694700C12574 /* VideoTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoTableViewCell.swift; sourceTree = ""; }; 51 | C9498EF620AE6C0F00C12574 /* StoryBoard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryBoard.swift; sourceTree = ""; }; 52 | C9ABF09020AE71E600061EDF /* VideoFullTransition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoFullTransition.swift; sourceTree = ""; }; 53 | C9ABF09220AE72C800061EDF /* Transition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Transition.swift; sourceTree = ""; }; 54 | C9ABF09420AE8AF900061EDF /* UIView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = ""; }; 55 | C9ABF09620AEB06F00061EDF /* VideoDetailTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoDetailTransition.swift; sourceTree = ""; }; 56 | C9ABF09820AECB7A00061EDF /* PlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerView.swift; sourceTree = ""; }; 57 | C9E38DE320B40AB3000A3B5B /* CAMediaTimingFunction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CAMediaTimingFunction+Extension.swift"; sourceTree = ""; }; 58 | C9E38DE820B412A6000A3B5B /* VideoCommentTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoCommentTableViewCell.swift; sourceTree = ""; }; 59 | /* End PBXFileReference section */ 60 | 61 | /* Begin PBXFrameworksBuildPhase section */ 62 | C9498EBA20AE651200C12574 /* Frameworks */ = { 63 | isa = PBXFrameworksBuildPhase; 64 | buildActionMask = 2147483647; 65 | files = ( 66 | ); 67 | runOnlyForDeploymentPostprocessing = 0; 68 | }; 69 | /* End PBXFrameworksBuildPhase section */ 70 | 71 | /* Begin PBXGroup section */ 72 | C9498EB420AE651200C12574 = { 73 | isa = PBXGroup; 74 | children = ( 75 | C9498EBF20AE651200C12574 /* VideoTransitionDemo */, 76 | C9498ED420AE651300C12574 /* VideoTransitionDemoTests */, 77 | C9498EDF20AE651300C12574 /* VideoTransitionDemoUITests */, 78 | C9498EBE20AE651200C12574 /* Products */, 79 | ); 80 | sourceTree = ""; 81 | }; 82 | C9498EBE20AE651200C12574 /* Products */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | C9498EBD20AE651200C12574 /* VideoTransitionDemo.app */, 86 | ); 87 | name = Products; 88 | sourceTree = ""; 89 | }; 90 | C9498EBF20AE651200C12574 /* VideoTransitionDemo */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | C9E38DE620B40D93000A3B5B /* Utils */, 94 | C9E38DE520B40D84000A3B5B /* Transition */, 95 | C9E38DE220B40A78000A3B5B /* Extension */, 96 | C9E38DE720B40DC6000A3B5B /* View */, 97 | C9498EC020AE651200C12574 /* AppDelegate.swift */, 98 | C9498EC220AE651200C12574 /* ViewController.swift */, 99 | C9498EEE20AE681100C12574 /* HorizontalFullViewController.swift */, 100 | C9498EF020AE682500C12574 /* VerticalFullViewController.swift */, 101 | C9498EF220AE683700C12574 /* DetailViewController.swift */, 102 | C92EC33120BBAF4500B26F00 /* CommentInputViewController.swift */, 103 | C9498EC420AE651200C12574 /* Main.storyboard */, 104 | C9498EC720AE651300C12574 /* Assets.xcassets */, 105 | C9498EC920AE651300C12574 /* LaunchScreen.storyboard */, 106 | C9498ECC20AE651300C12574 /* Info.plist */, 107 | ); 108 | path = VideoTransitionDemo; 109 | sourceTree = ""; 110 | }; 111 | C9498ED420AE651300C12574 /* VideoTransitionDemoTests */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | C9498ED520AE651300C12574 /* VideoTransitionDemoTests.swift */, 115 | C9498ED720AE651300C12574 /* Info.plist */, 116 | ); 117 | path = VideoTransitionDemoTests; 118 | sourceTree = ""; 119 | }; 120 | C9498EDF20AE651300C12574 /* VideoTransitionDemoUITests */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | C9498EE020AE651300C12574 /* VideoTransitionDemoUITests.swift */, 124 | C9498EE220AE651300C12574 /* Info.plist */, 125 | ); 126 | path = VideoTransitionDemoUITests; 127 | sourceTree = ""; 128 | }; 129 | C9E38DE220B40A78000A3B5B /* Extension */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | C9ABF09420AE8AF900061EDF /* UIView+Extension.swift */, 133 | C9E38DE320B40AB3000A3B5B /* CAMediaTimingFunction+Extension.swift */, 134 | ); 135 | path = Extension; 136 | sourceTree = ""; 137 | }; 138 | C9E38DE520B40D84000A3B5B /* Transition */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | C9ABF09220AE72C800061EDF /* Transition.swift */, 142 | C9ABF09020AE71E600061EDF /* VideoFullTransition.swift */, 143 | C9ABF09620AEB06F00061EDF /* VideoDetailTransition.swift */, 144 | ); 145 | path = Transition; 146 | sourceTree = ""; 147 | }; 148 | C9E38DE620B40D93000A3B5B /* Utils */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | C924519F2297A20A005EC0FA /* Auto.swift */, 152 | C924519E2297A20A005EC0FA /* Inch.swift */, 153 | C9498EF620AE6C0F00C12574 /* StoryBoard.swift */, 154 | ); 155 | path = Utils; 156 | sourceTree = ""; 157 | }; 158 | C9E38DE720B40DC6000A3B5B /* View */ = { 159 | isa = PBXGroup; 160 | children = ( 161 | C9498EF420AE694700C12574 /* VideoTableViewCell.swift */, 162 | C9E38DE820B412A6000A3B5B /* VideoCommentTableViewCell.swift */, 163 | C9ABF09820AECB7A00061EDF /* PlayerView.swift */, 164 | ); 165 | path = View; 166 | sourceTree = ""; 167 | }; 168 | /* End PBXGroup section */ 169 | 170 | /* Begin PBXNativeTarget section */ 171 | C9498EBC20AE651200C12574 /* VideoTransitionDemo */ = { 172 | isa = PBXNativeTarget; 173 | buildConfigurationList = C9498EE520AE651300C12574 /* Build configuration list for PBXNativeTarget "VideoTransitionDemo" */; 174 | buildPhases = ( 175 | C9498EB920AE651200C12574 /* Sources */, 176 | C9498EBA20AE651200C12574 /* Frameworks */, 177 | C9498EBB20AE651200C12574 /* Resources */, 178 | ); 179 | buildRules = ( 180 | ); 181 | dependencies = ( 182 | ); 183 | name = VideoTransitionDemo; 184 | productName = VideoTransitionDemo; 185 | productReference = C9498EBD20AE651200C12574 /* VideoTransitionDemo.app */; 186 | productType = "com.apple.product-type.application"; 187 | }; 188 | /* End PBXNativeTarget section */ 189 | 190 | /* Begin PBXProject section */ 191 | C9498EB520AE651200C12574 /* Project object */ = { 192 | isa = PBXProject; 193 | attributes = { 194 | LastSwiftUpdateCheck = 0930; 195 | LastUpgradeCheck = 0930; 196 | ORGANIZATIONNAME = "李响"; 197 | TargetAttributes = { 198 | C9498EBC20AE651200C12574 = { 199 | CreatedOnToolsVersion = 9.3; 200 | LastSwiftMigration = 1020; 201 | }; 202 | }; 203 | }; 204 | buildConfigurationList = C9498EB820AE651200C12574 /* Build configuration list for PBXProject "VideoTransitionDemo" */; 205 | compatibilityVersion = "Xcode 9.3"; 206 | developmentRegion = en; 207 | hasScannedForEncodings = 0; 208 | knownRegions = ( 209 | en, 210 | Base, 211 | ); 212 | mainGroup = C9498EB420AE651200C12574; 213 | productRefGroup = C9498EBE20AE651200C12574 /* Products */; 214 | projectDirPath = ""; 215 | projectRoot = ""; 216 | targets = ( 217 | C9498EBC20AE651200C12574 /* VideoTransitionDemo */, 218 | ); 219 | }; 220 | /* End PBXProject section */ 221 | 222 | /* Begin PBXResourcesBuildPhase section */ 223 | C9498EBB20AE651200C12574 /* Resources */ = { 224 | isa = PBXResourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | C9498ECB20AE651300C12574 /* LaunchScreen.storyboard in Resources */, 228 | C9498EC820AE651300C12574 /* Assets.xcassets in Resources */, 229 | C9498EC620AE651200C12574 /* Main.storyboard in Resources */, 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | /* End PBXResourcesBuildPhase section */ 234 | 235 | /* Begin PBXSourcesBuildPhase section */ 236 | C9498EB920AE651200C12574 /* Sources */ = { 237 | isa = PBXSourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | C9ABF09320AE72C900061EDF /* Transition.swift in Sources */, 241 | C9E38DE920B412A6000A3B5B /* VideoCommentTableViewCell.swift in Sources */, 242 | C9498EEF20AE681100C12574 /* HorizontalFullViewController.swift in Sources */, 243 | C9498EC320AE651200C12574 /* ViewController.swift in Sources */, 244 | C9ABF09920AECB7A00061EDF /* PlayerView.swift in Sources */, 245 | C9E38DE420B40AB3000A3B5B /* CAMediaTimingFunction+Extension.swift in Sources */, 246 | C9ABF09120AE71E600061EDF /* VideoFullTransition.swift in Sources */, 247 | C92451A02297A20A005EC0FA /* Inch.swift in Sources */, 248 | C9498EF320AE683700C12574 /* DetailViewController.swift in Sources */, 249 | C92EC33220BBAF4500B26F00 /* CommentInputViewController.swift in Sources */, 250 | C9ABF09720AEB06F00061EDF /* VideoDetailTransition.swift in Sources */, 251 | C9ABF09520AE8AF900061EDF /* UIView+Extension.swift in Sources */, 252 | C9498EF120AE682500C12574 /* VerticalFullViewController.swift in Sources */, 253 | C9498EC120AE651200C12574 /* AppDelegate.swift in Sources */, 254 | C9498EF720AE6C0F00C12574 /* StoryBoard.swift in Sources */, 255 | C9498EF520AE694700C12574 /* VideoTableViewCell.swift in Sources */, 256 | C92451A12297A20A005EC0FA /* Auto.swift in Sources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | /* End PBXSourcesBuildPhase section */ 261 | 262 | /* Begin PBXVariantGroup section */ 263 | C9498EC420AE651200C12574 /* Main.storyboard */ = { 264 | isa = PBXVariantGroup; 265 | children = ( 266 | C9498EC520AE651200C12574 /* Base */, 267 | ); 268 | name = Main.storyboard; 269 | sourceTree = ""; 270 | }; 271 | C9498EC920AE651300C12574 /* LaunchScreen.storyboard */ = { 272 | isa = PBXVariantGroup; 273 | children = ( 274 | C9498ECA20AE651300C12574 /* Base */, 275 | ); 276 | name = LaunchScreen.storyboard; 277 | sourceTree = ""; 278 | }; 279 | /* End PBXVariantGroup section */ 280 | 281 | /* Begin XCBuildConfiguration section */ 282 | C9498EE320AE651300C12574 /* Debug */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | ALWAYS_SEARCH_USER_PATHS = NO; 286 | CLANG_ANALYZER_NONNULL = YES; 287 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 288 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 289 | CLANG_CXX_LIBRARY = "libc++"; 290 | CLANG_ENABLE_MODULES = YES; 291 | CLANG_ENABLE_OBJC_ARC = YES; 292 | CLANG_ENABLE_OBJC_WEAK = YES; 293 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 294 | CLANG_WARN_BOOL_CONVERSION = YES; 295 | CLANG_WARN_COMMA = YES; 296 | CLANG_WARN_CONSTANT_CONVERSION = YES; 297 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 298 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 299 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 300 | CLANG_WARN_EMPTY_BODY = YES; 301 | CLANG_WARN_ENUM_CONVERSION = YES; 302 | CLANG_WARN_INFINITE_RECURSION = YES; 303 | CLANG_WARN_INT_CONVERSION = YES; 304 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 305 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 306 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 307 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 308 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 309 | CLANG_WARN_STRICT_PROTOTYPES = YES; 310 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 311 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 312 | CLANG_WARN_UNREACHABLE_CODE = YES; 313 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 314 | CODE_SIGN_IDENTITY = "iPhone Developer"; 315 | COPY_PHASE_STRIP = NO; 316 | DEBUG_INFORMATION_FORMAT = dwarf; 317 | ENABLE_STRICT_OBJC_MSGSEND = YES; 318 | ENABLE_TESTABILITY = YES; 319 | GCC_C_LANGUAGE_STANDARD = gnu11; 320 | GCC_DYNAMIC_NO_PIC = NO; 321 | GCC_NO_COMMON_BLOCKS = YES; 322 | GCC_OPTIMIZATION_LEVEL = 0; 323 | GCC_PREPROCESSOR_DEFINITIONS = ( 324 | "DEBUG=1", 325 | "$(inherited)", 326 | ); 327 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 328 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 329 | GCC_WARN_UNDECLARED_SELECTOR = YES; 330 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 331 | GCC_WARN_UNUSED_FUNCTION = YES; 332 | GCC_WARN_UNUSED_VARIABLE = YES; 333 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 334 | MTL_ENABLE_DEBUG_INFO = YES; 335 | ONLY_ACTIVE_ARCH = YES; 336 | SDKROOT = iphoneos; 337 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 338 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 339 | }; 340 | name = Debug; 341 | }; 342 | C9498EE420AE651300C12574 /* Release */ = { 343 | isa = XCBuildConfiguration; 344 | buildSettings = { 345 | ALWAYS_SEARCH_USER_PATHS = NO; 346 | CLANG_ANALYZER_NONNULL = YES; 347 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 348 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 349 | CLANG_CXX_LIBRARY = "libc++"; 350 | CLANG_ENABLE_MODULES = YES; 351 | CLANG_ENABLE_OBJC_ARC = YES; 352 | CLANG_ENABLE_OBJC_WEAK = YES; 353 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 354 | CLANG_WARN_BOOL_CONVERSION = YES; 355 | CLANG_WARN_COMMA = YES; 356 | CLANG_WARN_CONSTANT_CONVERSION = YES; 357 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 358 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 359 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 360 | CLANG_WARN_EMPTY_BODY = YES; 361 | CLANG_WARN_ENUM_CONVERSION = YES; 362 | CLANG_WARN_INFINITE_RECURSION = YES; 363 | CLANG_WARN_INT_CONVERSION = YES; 364 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 365 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 366 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 367 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 368 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 369 | CLANG_WARN_STRICT_PROTOTYPES = YES; 370 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 371 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 372 | CLANG_WARN_UNREACHABLE_CODE = YES; 373 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 374 | CODE_SIGN_IDENTITY = "iPhone Developer"; 375 | COPY_PHASE_STRIP = NO; 376 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 377 | ENABLE_NS_ASSERTIONS = NO; 378 | ENABLE_STRICT_OBJC_MSGSEND = YES; 379 | GCC_C_LANGUAGE_STANDARD = gnu11; 380 | GCC_NO_COMMON_BLOCKS = YES; 381 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 382 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 383 | GCC_WARN_UNDECLARED_SELECTOR = YES; 384 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 385 | GCC_WARN_UNUSED_FUNCTION = YES; 386 | GCC_WARN_UNUSED_VARIABLE = YES; 387 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 388 | MTL_ENABLE_DEBUG_INFO = NO; 389 | SDKROOT = iphoneos; 390 | SWIFT_COMPILATION_MODE = wholemodule; 391 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 392 | VALIDATE_PRODUCT = YES; 393 | }; 394 | name = Release; 395 | }; 396 | C9498EE620AE651300C12574 /* Debug */ = { 397 | isa = XCBuildConfiguration; 398 | buildSettings = { 399 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 400 | CODE_SIGN_STYLE = Automatic; 401 | DEVELOPMENT_TEAM = 683UGRW72Z; 402 | INFOPLIST_FILE = VideoTransitionDemo/Info.plist; 403 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 404 | LD_RUNPATH_SEARCH_PATHS = ( 405 | "$(inherited)", 406 | "@executable_path/Frameworks", 407 | ); 408 | PRODUCT_BUNDLE_IDENTIFIER = com.lee.VideoTransitionDemo; 409 | PRODUCT_NAME = "$(TARGET_NAME)"; 410 | SWIFT_VERSION = 5.0; 411 | TARGETED_DEVICE_FAMILY = "1,2"; 412 | }; 413 | name = Debug; 414 | }; 415 | C9498EE720AE651300C12574 /* Release */ = { 416 | isa = XCBuildConfiguration; 417 | buildSettings = { 418 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 419 | CODE_SIGN_STYLE = Automatic; 420 | DEVELOPMENT_TEAM = 683UGRW72Z; 421 | INFOPLIST_FILE = VideoTransitionDemo/Info.plist; 422 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 423 | LD_RUNPATH_SEARCH_PATHS = ( 424 | "$(inherited)", 425 | "@executable_path/Frameworks", 426 | ); 427 | PRODUCT_BUNDLE_IDENTIFIER = com.lee.VideoTransitionDemo; 428 | PRODUCT_NAME = "$(TARGET_NAME)"; 429 | SWIFT_VERSION = 5.0; 430 | TARGETED_DEVICE_FAMILY = "1,2"; 431 | }; 432 | name = Release; 433 | }; 434 | /* End XCBuildConfiguration section */ 435 | 436 | /* Begin XCConfigurationList section */ 437 | C9498EB820AE651200C12574 /* Build configuration list for PBXProject "VideoTransitionDemo" */ = { 438 | isa = XCConfigurationList; 439 | buildConfigurations = ( 440 | C9498EE320AE651300C12574 /* Debug */, 441 | C9498EE420AE651300C12574 /* Release */, 442 | ); 443 | defaultConfigurationIsVisible = 0; 444 | defaultConfigurationName = Release; 445 | }; 446 | C9498EE520AE651300C12574 /* Build configuration list for PBXNativeTarget "VideoTransitionDemo" */ = { 447 | isa = XCConfigurationList; 448 | buildConfigurations = ( 449 | C9498EE620AE651300C12574 /* Debug */, 450 | C9498EE720AE651300C12574 /* Release */, 451 | ); 452 | defaultConfigurationIsVisible = 0; 453 | defaultConfigurationName = Release; 454 | }; 455 | /* End XCConfigurationList section */ 456 | }; 457 | rootObject = C9498EB520AE651200C12574 /* Project object */; 458 | } 459 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { 45 | return .allButUpsideDown 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/navigation_back.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "navigation_back.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "preserves-vector-representation" : true 14 | } 15 | } -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/navigation_back.imageset/navigation_back.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lixiang1994/VideoTransitionDemo/60a2d0dafb6c04736f67db6a58c56cc8d09962a4/VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/navigation_back.imageset/navigation_back.pdf -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/video_full.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "video_full.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "preserves-vector-representation" : true 14 | } 15 | } -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/video_full.imageset/video_full.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lixiang1994/VideoTransitionDemo/60a2d0dafb6c04736f67db6a58c56cc8d09962a4/VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/video_full.imageset/video_full.pdf -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/video_small.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "video_small.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "preserves-vector-representation" : true 14 | } 15 | } -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/video_small.imageset/video_small.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lixiang1994/VideoTransitionDemo/60a2d0dafb6c04736f67db6a58c56cc8d09962a4/VideoTransitionDemo/VideoTransitionDemo/Assets.xcassets/video_small.imageset/video_small.pdf -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 44 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 109 | 110 | 111 | 112 | 113 | 124 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 177 | 178 | 179 | 180 | 181 | 192 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 263 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/CommentInputViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CommentInputViewController.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol CommentInputViewControllerDelegate: NSObjectProtocol { 12 | func send(content: String, completion: @escaping (Bool)->Void) 13 | } 14 | 15 | class CommentInputViewController: UIViewController { 16 | 17 | weak var delegate: CommentInputViewControllerDelegate? 18 | 19 | @IBOutlet weak var editView: UIView! 20 | @IBOutlet weak var textView: UITextView! 21 | @IBOutlet weak var sendButton: UIButton! 22 | 23 | @IBOutlet weak var editHeightConstraint: NSLayoutConstraint! 24 | @IBOutlet weak var textHeightConstraint: NSLayoutConstraint! 25 | @IBOutlet weak var bottomConstraint: NSLayoutConstraint! 26 | 27 | private var sending: Bool = false 28 | private var closing: Bool = false 29 | 30 | private let maxWordNumber = 100 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | setup() 36 | setupLayout() 37 | setupNotification() 38 | 39 | textView.becomeFirstResponder() 40 | } 41 | 42 | private func setup() { 43 | textView.font = .systemFont(ofSize: 14.0) 44 | textView.textContainerInset = UIEdgeInsets(top: 10.5, left: 8, bottom: 10.5, right: 8) 45 | } 46 | 47 | private func setupLayout() { 48 | bottomConstraint.constant = -editHeightConstraint.constant 49 | } 50 | 51 | private func setupNotification() { 52 | NotificationCenter.default.addObserver( 53 | self, 54 | selector: #selector(keyboardWillChangeFrame), 55 | name: UIResponder.keyboardWillChangeFrameNotification, 56 | object: nil 57 | ) 58 | } 59 | 60 | @objc private func keyboardWillChangeFrame(_ notify: Notification) { 61 | guard let info = notify.userInfo else { 62 | return 63 | } 64 | guard let local = info[UIResponder.keyboardIsLocalUserInfoKey] as? Int, local == 1 else { 65 | return 66 | } 67 | guard 68 | let duration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as?TimeInterval, 69 | let curveRaw = info[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int, 70 | let curve = UIView.AnimationCurve(rawValue: curveRaw), 71 | let endRect = info[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { 72 | return 73 | } 74 | 75 | handleKeyboard(duration: duration, curve: curve, endRect: endRect) 76 | } 77 | 78 | @IBAction func sendAction(_ sender: UIButton) { 79 | sending = true 80 | sender.startLoading(.gray) 81 | let content = textView.text 82 | .prefix(maxWordNumber) 83 | .replacingOccurrences(of: "\n", with: " ") 84 | 85 | delegate?.send(content: content, completion: { [weak self] (result) in 86 | guard let this = self else { return } 87 | this.sending = false 88 | if result { 89 | this.closing = true 90 | this.textView.resignFirstResponder() 91 | } else { 92 | sender.stopLoading() 93 | } 94 | }) 95 | } 96 | 97 | override func touchesBegan(_ touches: Set, with event: UIEvent?) { 98 | super.touchesBegan(touches, with: event) 99 | guard 100 | let first = touches.first, 101 | !editView.frame.contains(first.location(in: view)) else { 102 | return 103 | } 104 | closing = true 105 | view.endEditing(true) 106 | } 107 | 108 | @discardableResult 109 | class func present(_ controller: T) -> CommentInputViewController { 110 | let vc = CommentInputViewController.instance() 111 | vc.modalPresentationStyle = .overFullScreen 112 | vc.delegate = controller 113 | controller.present(vc, animated: true, completion: nil) 114 | return vc 115 | } 116 | 117 | class func instance() -> Self { 118 | return StoryBoard.main.instance() 119 | } 120 | 121 | deinit { print("CommentInputViewController deinit") } 122 | } 123 | 124 | extension CommentInputViewController { 125 | 126 | private func handleKeyboard(duration: TimeInterval, curve: UIView.AnimationCurve, endRect: CGRect) { 127 | var closing = self.closing 128 | let bounds = UIScreen.main.bounds 129 | let offset = endRect.origin.y.rounded() 130 | let hide = offset == bounds.height || offset == bounds.width 131 | if hide { 132 | closing = true 133 | self.closing = closing 134 | bottomConstraint.constant = -editHeightConstraint.constant 135 | } else { 136 | bottomConstraint.constant = endRect.height 137 | } 138 | UIView.animate(withDuration: duration, animations: { 139 | UIView.setAnimationCurve(curve) 140 | self.view.setNeedsLayout() 141 | self.view.layoutIfNeeded() 142 | }) { [weak self] _ in 143 | if hide, closing { self?.dismiss(animated: true, completion: nil) } 144 | } 145 | } 146 | 147 | private func updateTextViewHeight(height: CGFloat , animated: Bool) { 148 | textHeightConstraint.constant = height 149 | editHeightConstraint.constant = height + 16.0 150 | UIView.beginAnimations("height", context: nil) 151 | UIView.setAnimationDuration(0.2) 152 | UIView.setAnimationsEnabled(animated) 153 | view.layoutIfNeeded() 154 | UIView.commitAnimations() 155 | } 156 | } 157 | 158 | extension CommentInputViewController: UITextViewDelegate { 159 | 160 | func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { 161 | guard sending == false else { return false } 162 | 163 | if range.location < maxWordNumber { 164 | return true 165 | } else if range.location < textView.text.count { 166 | // 超过规定字数,只能删除,不能添加 167 | return true 168 | } else { 169 | return false 170 | } 171 | } 172 | 173 | func textViewDidChange(_ textView: UITextView) { 174 | guard let lineHeight = textView.font?.lineHeight else { return } 175 | 176 | let maxRow = 6 177 | let maxHeight = ceilf(Float(lineHeight * CGFloat(maxRow) + textView.textContainerInset.top + textView.textContainerInset.bottom)) 178 | let size = textView.sizeThatFits(CGSize(width: textView.bounds.width, height: CGFloat(MAXFLOAT))) 179 | let height = ceilf(Float(size.height)) 180 | let currentHeight = ceilf(Float(textView.bounds.height)) 181 | textView.isScrollEnabled = height > maxHeight && maxHeight > 0 182 | let targetHeight = textView.isScrollEnabled ? maxHeight : height 183 | if currentHeight != targetHeight { 184 | updateTextViewHeight(height: CGFloat(targetHeight), animated: true) 185 | } 186 | 187 | sendButton.isEnabled = textView.text.count != 0 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/DetailViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Foundation 11 | 12 | enum DetailType { 13 | case horizontal 14 | case vertical 15 | } 16 | 17 | class DetailViewController: UIViewController { 18 | 19 | var type: DetailType = .horizontal 20 | 21 | lazy var transition: Transition = { 22 | loadViewIfNeeded() 23 | $0.targetView = playerView 24 | $0.targetGravity = .resizeAspect 25 | return $0 26 | } ( VideoDetailTransition() ) 27 | 28 | @IBOutlet weak var backButton: UIButton! 29 | @IBOutlet weak var fullButton: UIButton! 30 | @IBOutlet weak var playerView: PlayerView! 31 | @IBOutlet weak var tableView: UITableView! 32 | 33 | @IBOutlet weak var statusHeightConstraint: NSLayoutConstraint! 34 | 35 | override func viewDidLoad() { 36 | super.viewDidLoad() 37 | 38 | setup() 39 | setupLayout() 40 | } 41 | 42 | override func viewDidAppear(_ animated: Bool) { 43 | super.viewDidAppear(animated) 44 | 45 | showControls() 46 | 47 | NotificationCenter.default.addObserver( 48 | self, 49 | selector: #selector(deviceOrientationDidChange), 50 | name: UIDevice.orientationDidChangeNotification, 51 | object: nil 52 | ) 53 | } 54 | 55 | override func viewDidDisappear(_ animated: Bool) { 56 | super.viewDidDisappear(animated) 57 | 58 | NotificationCenter.default.removeObserver( 59 | self, 60 | name: UIDevice.orientationDidChangeNotification, 61 | object: nil 62 | ) 63 | } 64 | 65 | override func viewWillAppear(_ animated: Bool) { 66 | super.viewWillAppear(animated) 67 | // 解决横竖屏切换时 view异常 68 | view.frame = UIScreen.main.bounds 69 | } 70 | 71 | private func setup() { 72 | backButton.alpha = 0 73 | fullButton.alpha = 0 74 | } 75 | 76 | private func setupLayout() { 77 | statusHeightConstraint.constant = CGFloat(20).ifull(44) 78 | } 79 | 80 | @objc private func deviceOrientationDidChange() { 81 | guard shouldAutorotate else { return } 82 | guard presentedViewController == nil else { return } 83 | guard type == .horizontal else { return } 84 | 85 | switch UIDevice.current.orientation { 86 | case .landscapeRight, .landscapeLeft: 87 | gotoFull() 88 | default: break 89 | } 90 | } 91 | 92 | private func gotoFull() { 93 | if presentingViewController is VideoFullable { 94 | dismiss(animated: true) { } 95 | } else { 96 | switch type { 97 | case .horizontal: 98 | var orientation: UIInterfaceOrientation = UIDevice.current.orientation == .landscapeRight ? .landscapeLeft : .landscapeRight 99 | orientation = shouldAutorotate ? orientation : .landscapeRight 100 | let controller = HorizontalFullViewController.instance() 101 | let transition = controller.transition as! VideoFullTransition 102 | transition.sourceView = playerView 103 | transition.sourceGravity = .resizeAspect 104 | controller.preferredOrientation = orientation 105 | controller.modalPresentationStyle = .fullScreen 106 | controller.transitioningDelegate = transition 107 | present(controller, animated: true) { } 108 | case .vertical: 109 | let controller = VerticalFullViewController.instance() 110 | let transition = controller.transition as! VideoFullTransition 111 | transition.sourceView = playerView 112 | transition.sourceGravity = .resizeAspect 113 | controller.modalPresentationStyle = .fullScreen 114 | controller.transitioningDelegate = transition 115 | present(controller, animated: true) { } 116 | } 117 | } 118 | 119 | hideControls() 120 | } 121 | 122 | @IBAction func backAction(_ sender: Any) { 123 | dismiss(animated: true) { } 124 | } 125 | 126 | @IBAction func fullAction(_ sender: Any) { 127 | gotoFull() 128 | } 129 | @IBAction func commentAction(_ sender: Any) { 130 | CommentInputViewController.present(self) 131 | } 132 | 133 | override var shouldAutorotate: Bool { 134 | return true 135 | } 136 | 137 | override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 138 | return .portrait 139 | } 140 | 141 | override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { 142 | return .portrait 143 | } 144 | 145 | class func instance() -> Self { 146 | return StoryBoard.main.instance() 147 | } 148 | 149 | deinit { print("DetailViewController deinit") } 150 | } 151 | 152 | extension DetailViewController { 153 | 154 | /// 显示控件 155 | private func showControls() { 156 | UIView.beginAnimations("", context: nil) 157 | backButton.alpha = 1.0 158 | fullButton.alpha = 1.0 159 | UIView.commitAnimations() 160 | } 161 | 162 | /// 隐藏控件 163 | private func hideControls() { 164 | UIView.beginAnimations("", context: nil) 165 | backButton.alpha = 0 166 | fullButton.alpha = 0 167 | UIView.commitAnimations() 168 | } 169 | } 170 | 171 | extension DetailViewController: CommentInputViewControllerDelegate { 172 | 173 | func send(content: String, completion: @escaping (Bool) -> Void) { 174 | DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { 175 | completion(true) 176 | } 177 | } 178 | } 179 | 180 | extension DetailViewController: UITableViewDataSource { 181 | 182 | func numberOfSections(in tableView: UITableView) -> Int { 183 | return 1 184 | } 185 | 186 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 187 | return 10 188 | } 189 | 190 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 191 | let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 192 | return cell 193 | } 194 | } 195 | 196 | extension DetailViewController: UITableViewDelegate { 197 | 198 | } 199 | 200 | extension DetailViewController: TransitionTarget { } 201 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Extension/CAMediaTimingFunction+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CAMediaTimingFunction+Extension.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/22. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension CAMediaTimingFunction { 12 | // default 13 | public static let linear = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) 14 | public static let easeIn = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) 15 | public static let easeOut = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) 16 | public static let easeInOut = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) 17 | 18 | // material 19 | public static let standard = CAMediaTimingFunction(controlPoints: 0.4, 0.0, 0.2, 1.0) 20 | public static let deceleration = CAMediaTimingFunction(controlPoints: 0.0, 0.0, 0.2, 1) 21 | public static let acceleration = CAMediaTimingFunction(controlPoints: 0.4, 0.0, 1, 1) 22 | public static let sharp = CAMediaTimingFunction(controlPoints: 0.4, 0.0, 0.6, 1) 23 | 24 | // easing.net 25 | public static let easeOutBack = CAMediaTimingFunction(controlPoints: 0.175, 0.885, 0.32, 1.275) 26 | 27 | static func from(name: String) -> CAMediaTimingFunction? { 28 | switch name { 29 | case "linear": 30 | return .linear 31 | case "easeIn": 32 | return .easeIn 33 | case "easeOut": 34 | return .easeOut 35 | case "easeInOut": 36 | return .easeInOut 37 | case "standard": 38 | return .standard 39 | case "deceleration": 40 | return .deceleration 41 | case "acceleration": 42 | return .acceleration 43 | case "sharp": 44 | return .sharp 45 | default: 46 | return nil 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Extension/UIView+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Extension.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | extension UIView { 13 | 14 | func startLoading(_ activityIndicatorStyle: UIActivityIndicatorView.Style = .white) { 15 | stopLoading() 16 | 17 | let maskView = UIView(frame: bounds) 18 | 19 | addSubview(maskView) 20 | maskView.tag = 1994 21 | 22 | if let button = self as? UIButton { 23 | button.titleLabel?.alpha = 0.0 24 | button.imageView?.alpha = 0.0 25 | } 26 | maskView.backgroundColor = backgroundColor 27 | 28 | let load = UIActivityIndicatorView(style: activityIndicatorStyle) 29 | 30 | maskView.addSubview(load) 31 | load.center = maskView.center 32 | load.startAnimating() 33 | } 34 | 35 | func stopLoading() { 36 | guard let maskView = viewWithTag(1994) else { return } 37 | 38 | if let button = self as? UIButton { 39 | button.titleLabel?.alpha = 1.0 40 | button.imageView?.alpha = 1.0 41 | } 42 | maskView.removeFromSuperview() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/HorizontalFullViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HorizontalFullViewController.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class HorizontalFullViewController: UIViewController { 12 | 13 | lazy var transition: Transition = { 14 | loadViewIfNeeded() 15 | $0.targetView = playerView 16 | $0.targetGravity = .resizeAspect 17 | return $0 18 | } ( VideoFullTransition() ) 19 | 20 | /// 优先方向 用于判断过渡时的方向 同步旋转屏幕时的过渡旋转效果 21 | lazy var preferredOrientation: UIInterfaceOrientation = .landscapeRight 22 | 23 | /// 详情控制器 持有 防止每次初始化新的 24 | lazy var detailController: DetailViewController = .instance() 25 | 26 | @IBOutlet weak var playerView: PlayerView! 27 | @IBOutlet weak var backButton: UIButton! 28 | @IBOutlet weak var detailButton: UIButton! 29 | 30 | @IBOutlet weak var statusHeightConstraint: NSLayoutConstraint! 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | setup() 36 | setupLayout() 37 | setupNotification() 38 | } 39 | 40 | override func viewWillAppear(_ animated: Bool) { 41 | super.viewWillAppear(animated) 42 | // 解决横竖屏切换时 view异常 43 | view.frame = UIScreen.main.bounds 44 | } 45 | 46 | override func viewDidAppear(_ animated: Bool) { 47 | super.viewDidAppear(animated) 48 | // 显示控件 优化过渡效果 49 | showControls() 50 | } 51 | 52 | private func setup() { 53 | backButton.alpha = 0 54 | detailButton.alpha = 0 55 | } 56 | 57 | private func setupLayout() { 58 | statusHeightConstraint.constant = 0 59 | } 60 | 61 | private func setupNotification() { 62 | NotificationCenter.default.addObserver( 63 | self, 64 | selector: #selector(deviceOrientationDidChange), 65 | name: UIDevice.orientationDidChangeNotification, 66 | object: nil 67 | ) 68 | } 69 | 70 | @objc func deviceOrientationDidChange() { 71 | guard shouldAutorotate else { return } 72 | 73 | switch UIDevice.current.orientation { 74 | case .portrait: 75 | guard presentedViewController == nil else { return } 76 | gotoDetail() 77 | case .landscapeLeft: 78 | preferredOrientation = .landscapeRight 79 | case .landscapeRight: 80 | preferredOrientation = .landscapeLeft 81 | default: break 82 | } 83 | } 84 | 85 | private func gotoDetail() { 86 | if presentingViewController is DetailViewController { 87 | dismiss(animated: true) { } 88 | } else { 89 | let controller = detailController 90 | let transition = controller.transition as! VideoDetailTransition 91 | transition.sourceView = playerView 92 | transition.sourceGravity = .resizeAspect 93 | controller.type = .horizontal 94 | controller.modalPresentationStyle = .fullScreen 95 | controller.transitioningDelegate = transition 96 | present(controller, animated: true) { } 97 | } 98 | } 99 | 100 | @IBAction func backAction(_ sender: Any) { 101 | dismiss(animated: true) { } 102 | } 103 | 104 | @IBAction func detailAction(_ sender: Any) { 105 | gotoDetail() 106 | } 107 | 108 | override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { 109 | super.present(viewControllerToPresent, animated: flag, completion: completion) 110 | 111 | hideControls() 112 | } 113 | 114 | override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { 115 | super.dismiss(animated: flag, completion: completion) 116 | 117 | hideControls() 118 | } 119 | 120 | override var shouldAutorotate: Bool { 121 | return true 122 | } 123 | 124 | override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 125 | return .landscape 126 | } 127 | 128 | override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { 129 | return preferredOrientation 130 | } 131 | 132 | class func instance() -> Self { 133 | return StoryBoard.main.instance() 134 | } 135 | 136 | deinit { print("HorizontalFullViewController deinit") } 137 | } 138 | 139 | extension HorizontalFullViewController { 140 | 141 | /// 显示控件 142 | private func showControls() { 143 | UIView.beginAnimations("", context: nil) 144 | backButton.alpha = 1.0 145 | detailButton.alpha = 1.0 146 | UIView.commitAnimations() 147 | } 148 | 149 | /// 隐藏控件 150 | private func hideControls() { 151 | backButton.alpha = 0 152 | detailButton.alpha = 0 153 | } 154 | } 155 | 156 | extension HorizontalFullViewController: VideoFullable { } 157 | extension HorizontalFullViewController: TransitionTarget { } 158 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | VideoTransition 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Transition/Transition.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Transition.swift 3 | // LiveTrivia 4 | // 5 | // Created by 李响 on 2017/11/29. 6 | // Copyright © 2017年 LiveTrivia. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | enum TransitionType { 12 | case present 13 | case dismiss 14 | } 15 | 16 | typealias Transition = UIViewControllerTransitioningDelegate 17 | 18 | protocol TransitionTarget { 19 | var transition: Transition { get } 20 | } 21 | 22 | extension UIViewController { 23 | 24 | func presentWithTransition(_ vc: T, completion: (() -> Void)? = nil) { 25 | vc.transitioningDelegate = vc.transition 26 | vc.modalPresentationStyle = .fullScreen 27 | present(vc, animated: true, completion: completion) 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Transition/VideoDetailTransition.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VideoDetailTransition.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | import AVKit 12 | 13 | /* 14 | 视频详情过渡 15 | 动画视图为临时view 16 | 从来源视图的大小动画到详情视图大小 (详情视图大小位置固定) 17 | 如果来源VC的优先方向是横屏 那么动画中增加旋转 18 | dismiss时根据目标VC的横竖屏方向支持判断是否需要做旋转处理 19 | */ 20 | 21 | class VideoDetailTransition: NSObject, UIViewControllerTransitioningDelegate { 22 | 23 | public var sourceView: UIView? 24 | public var targetView: UIView? 25 | public var sourceGravity: AVLayerVideoGravity = .resizeAspect 26 | public var targetGravity: AVLayerVideoGravity = .resizeAspect 27 | 28 | public var presentDuration: TimeInterval = 0.3 29 | public var dismissDuration: TimeInterval = 0.3 30 | 31 | func animationController(forPresented presented: UIViewController, 32 | presenting: UIViewController, 33 | source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 34 | let transitioning = VideoDetailAnimatedTransitioning(.present) 35 | transitioning.duration = presentDuration 36 | transitioning.sourceView = sourceView 37 | transitioning.targetView = targetView 38 | transitioning.sourceGravity = sourceGravity 39 | transitioning.targetGravity = targetGravity 40 | return transitioning 41 | } 42 | 43 | func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 44 | let transitioning = VideoDetailAnimatedTransitioning(.dismiss) 45 | transitioning.duration = dismissDuration 46 | transitioning.sourceView = targetView 47 | transitioning.targetView = sourceView 48 | transitioning.sourceGravity = targetGravity 49 | transitioning.targetGravity = sourceGravity 50 | return transitioning 51 | } 52 | } 53 | 54 | class VideoDetailAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning { 55 | 56 | public var sourceView: UIView? 57 | public var targetView: UIView? 58 | public var sourceGravity: AVLayerVideoGravity = .resizeAspect 59 | public var targetGravity: AVLayerVideoGravity = .resizeAspect 60 | 61 | public var duration: TimeInterval = 0.5 62 | 63 | let type: TransitionType 64 | 65 | init(_ type: TransitionType) { 66 | self.type = type 67 | super.init() 68 | } 69 | 70 | func presentAnimation(_ transitionContext: UIViewControllerContextTransitioning) { 71 | guard 72 | let fromViewController = transitionContext.viewController(forKey: .from), 73 | let fromView = fromViewController.view, 74 | let toViewController = transitionContext.viewController(forKey: .to), 75 | let toView = toViewController.view else { return } 76 | guard let sourceView = sourceView, let targetView = targetView else { return } 77 | 78 | fromView.layoutIfNeeded() 79 | toView.layoutIfNeeded() 80 | 81 | let containerView = transitionContext.containerView 82 | let sourceCenter = sourceView.superview!.convert(sourceView.center, to: containerView) 83 | let targetRect = targetView.convert(targetView.bounds, to: containerView) 84 | 85 | toView.alpha = 0.0 86 | toView.clipsToBounds = true 87 | toView.bounds = containerView.bounds 88 | toView.center = containerView.center 89 | containerView.addSubview(toView) 90 | 91 | let tempView = PlayerView() 92 | tempView.clipsToBounds = true 93 | tempView.backgroundColor = .black 94 | tempView.bounds = sourceView.bounds 95 | tempView.center = sourceCenter 96 | containerView.addSubview(tempView) 97 | 98 | // 根据来自VC的优先方向设置临时视图旋转 (跳转横全屏时) 99 | switch fromViewController.preferredInterfaceOrientationForPresentation { 100 | case .landscapeLeft: 101 | tempView.transform = CGAffineTransform(rotationAngle: CGFloat(-Double.pi / 2)) 102 | case .landscapeRight: 103 | tempView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2)) 104 | default: break 105 | } 106 | // 设置layer 107 | playerLayer.frame = tempView.bounds 108 | tempView.layer.addSublayer(playerLayer) 109 | 110 | let duration = transitionDuration(using: transitionContext) 111 | 112 | UIView.animate( 113 | withDuration: duration, 114 | delay: 0, 115 | options: .layoutSubviews, 116 | animations: { 117 | tempView.transform = .identity 118 | tempView.frame = targetRect 119 | toView.alpha = 1.0 120 | 121 | CATransaction.begin() 122 | CATransaction.setAnimationDuration(duration) 123 | CATransaction.setAnimationTimingFunction(.easeInOut) 124 | playerLayer.videoGravity = self.targetGravity 125 | CATransaction.commit() 126 | }) { (_) in 127 | // 移除临时视图 128 | tempView.removeFromSuperview() 129 | 130 | // 设置layer 131 | playerLayer.frame = targetView.bounds 132 | targetView.layer.addSublayer(playerLayer) 133 | 134 | transitionContext.completeTransition(!transitionContext.transitionWasCancelled) 135 | } 136 | } 137 | 138 | func dismissAnimation(_ transitionContext: UIViewControllerContextTransitioning) { 139 | guard let toViewController = transitionContext.viewController(forKey: .to) else { return } 140 | guard let fromView = transitionContext.view(forKey: .from) else { return } 141 | guard let toView = toViewController.view else { return } 142 | guard let sourceView = sourceView, let targetView = targetView else { return } 143 | 144 | fromView.layoutIfNeeded() 145 | toView.layoutIfNeeded() 146 | 147 | let containerView = transitionContext.containerView 148 | let sourceCenter = sourceView.superview!.convert(sourceView.center, to: containerView) 149 | let targetRect = targetView.convert(targetView.bounds, to: containerView) 150 | 151 | containerView.insertSubview(toView, belowSubview: fromView) 152 | 153 | let tempView = PlayerView() 154 | tempView.clipsToBounds = true 155 | tempView.backgroundColor = .black 156 | tempView.bounds = sourceView.bounds 157 | tempView.center = sourceCenter 158 | containerView.addSubview(tempView) 159 | 160 | // 根据VC支持的屏幕方向和当前屏幕方向设置旋转 (返回横全屏时) 161 | switch toViewController.preferredInterfaceOrientationForPresentation { 162 | case .landscapeLeft: 163 | tempView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2)) 164 | case .landscapeRight: 165 | tempView.transform = CGAffineTransform(rotationAngle: CGFloat(-Double.pi / 2)) 166 | default: break 167 | } 168 | 169 | // 设置layer 170 | playerLayer.frame = tempView.bounds 171 | tempView.layer.addSublayer(playerLayer) 172 | 173 | let duration = transitionDuration(using: transitionContext) 174 | 175 | UIView.animate( 176 | withDuration: duration, 177 | delay: 0, 178 | options: .layoutSubviews, 179 | animations: { 180 | tempView.transform = .identity 181 | tempView.frame = targetRect 182 | fromView.alpha = 0.0 183 | 184 | CATransaction.begin() 185 | CATransaction.setAnimationDuration(duration) 186 | CATransaction.setAnimationTimingFunction(.easeInOut) 187 | playerLayer.videoGravity = self.targetGravity 188 | CATransaction.commit() 189 | }) { (_) in 190 | // 移除临时视图 191 | fromView.removeFromSuperview() 192 | tempView.removeFromSuperview() 193 | 194 | // 设置layer 195 | playerLayer.frame = targetView.bounds 196 | targetView.layer.addSublayer(playerLayer) 197 | targetView.layer.insertSublayer(playerLayer, at: 0) 198 | 199 | transitionContext.completeTransition(!transitionContext.transitionWasCancelled) 200 | } 201 | } 202 | 203 | func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 204 | return duration 205 | } 206 | 207 | func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 208 | switch type { 209 | case .present: 210 | presentAnimation(transitionContext) 211 | case .dismiss: 212 | dismissAnimation(transitionContext) 213 | } 214 | } 215 | } 216 | 217 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Transition/VideoFullTransition.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VideoTransition.swift 3 | // LiveTrivia 4 | // 5 | // Created by 李响 on 2018/5/10. 6 | // Copyright © 2018年 LiveTrivia. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | import AVKit 12 | 13 | /* 14 | 视频全屏过渡 15 | 动画视图为全屏VC的view 16 | 从来源视图的大小动画到全屏大小 17 | 如果全屏VC的优先方向是横屏 那么动画中增加旋转 18 | */ 19 | 20 | protocol VideoFullable: NSObjectProtocol {} 21 | 22 | class VideoFullTransition: NSObject, UIViewControllerTransitioningDelegate { 23 | 24 | public var sourceView: UIView? 25 | public var targetView: UIView? 26 | public var sourceGravity: AVLayerVideoGravity = .resizeAspect 27 | public var targetGravity: AVLayerVideoGravity = .resizeAspect 28 | 29 | public var presentDuration: TimeInterval = 0.3 30 | public var dismissDuration: TimeInterval = 0.3 31 | 32 | func animationController(forPresented presented: UIViewController, 33 | presenting: UIViewController, 34 | source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 35 | let transitioning = VideoFullAnimatedTransitioning(.present) 36 | transitioning.duration = presentDuration 37 | transitioning.sourceView = sourceView 38 | transitioning.targetView = targetView 39 | transitioning.sourceGravity = sourceGravity 40 | transitioning.targetGravity = targetGravity 41 | return transitioning 42 | } 43 | 44 | func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 45 | let transitioning = VideoFullAnimatedTransitioning(.dismiss) 46 | transitioning.duration = dismissDuration 47 | transitioning.sourceView = targetView 48 | transitioning.targetView = sourceView 49 | transitioning.sourceGravity = targetGravity 50 | transitioning.targetGravity = sourceGravity 51 | return transitioning 52 | } 53 | } 54 | 55 | class VideoFullAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning { 56 | 57 | public var sourceView: UIView? 58 | public var targetView: UIView? 59 | public var sourceGravity: AVLayerVideoGravity = .resizeAspect 60 | public var targetGravity: AVLayerVideoGravity = .resizeAspect 61 | 62 | public var duration: TimeInterval = 0.5 63 | 64 | let type: TransitionType 65 | 66 | init(_ type: TransitionType) { 67 | self.type = type 68 | super.init() 69 | } 70 | 71 | func presentAnimation(_ transitionContext: UIViewControllerContextTransitioning) { 72 | guard 73 | let fromViewController = transitionContext.viewController(forKey: .from), 74 | let fromView = fromViewController.view, 75 | let toViewController = transitionContext.viewController(forKey: .to), 76 | let toView = toViewController.view else { return } 77 | guard let sourceView = sourceView, let targetView = targetView else { return } 78 | 79 | fromView.layoutIfNeeded() 80 | toView.layoutIfNeeded() 81 | 82 | let containerView = transitionContext.containerView 83 | let sourceCenter = sourceView.superview!.convert(sourceView.center, to: containerView) 84 | 85 | toView.clipsToBounds = true 86 | toView.bounds = sourceView.bounds 87 | toView.center = sourceCenter 88 | toView.setNeedsLayout() 89 | toView.layoutIfNeeded() 90 | containerView.addSubview(toView) 91 | 92 | // 根据目标VC的优先方向设置目标视图的旋转 93 | switch toViewController.preferredInterfaceOrientationForPresentation { 94 | case .landscapeLeft: 95 | toView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2)) 96 | case .landscapeRight: 97 | toView.transform = CGAffineTransform(rotationAngle: CGFloat(-Double.pi / 2)) 98 | default: break 99 | } 100 | 101 | // 设置layer 102 | playerLayer.frame = targetView.bounds 103 | targetView.layer.addSublayer(playerLayer) 104 | 105 | let duration = transitionDuration(using: transitionContext) 106 | 107 | UIView.animate( 108 | withDuration: duration, 109 | delay: 0, 110 | options: .layoutSubviews, 111 | animations: { 112 | 113 | toView.transform = .identity 114 | toView.bounds = containerView.bounds 115 | toView.center = containerView.center 116 | toView.layoutIfNeeded() 117 | 118 | CATransaction.begin() 119 | CATransaction.setAnimationDuration(duration) 120 | CATransaction.setAnimationTimingFunction(.easeInOut) 121 | playerLayer.videoGravity = self.targetGravity 122 | CATransaction.commit() 123 | }) { (_) in 124 | 125 | toView.transform = .identity 126 | toView.bounds = containerView.bounds 127 | toView.center = containerView.center 128 | transitionContext.completeTransition(!transitionContext.transitionWasCancelled) 129 | } 130 | } 131 | 132 | func dismissAnimation(_ transitionContext: UIViewControllerContextTransitioning) { 133 | guard let fromView = transitionContext.view(forKey: .from) else { return } 134 | guard let toView = transitionContext.view(forKey: .to) else { return } 135 | guard let targetView = targetView else { return } 136 | 137 | fromView.layoutIfNeeded() 138 | toView.layoutIfNeeded() 139 | 140 | let containerView = transitionContext.containerView 141 | let targetRect = targetView.convert(targetView.bounds, to: containerView) 142 | 143 | containerView.insertSubview(toView, belowSubview: fromView) 144 | 145 | let duration = transitionDuration(using: transitionContext) 146 | 147 | UIView.animate( 148 | withDuration: duration, 149 | delay: 0, 150 | options: .layoutSubviews, 151 | animations: { 152 | fromView.transform = .identity 153 | fromView.frame = targetRect 154 | fromView.layoutIfNeeded() 155 | 156 | CATransaction.begin() 157 | CATransaction.setAnimationDuration(duration) 158 | CATransaction.setAnimationTimingFunction(.easeInOut) 159 | playerLayer.videoGravity = self.targetGravity 160 | CATransaction.commit() 161 | }) { (_) in 162 | // 移除视图 163 | fromView.removeFromSuperview() 164 | 165 | // 设置layer 166 | playerLayer.frame = targetView.bounds 167 | targetView.layer.addSublayer(playerLayer) 168 | targetView.layer.insertSublayer(playerLayer, at: 0) 169 | 170 | transitionContext.completeTransition(!transitionContext.transitionWasCancelled) 171 | } 172 | } 173 | 174 | func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 175 | return duration 176 | } 177 | 178 | func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 179 | switch type { 180 | case .present: 181 | presentAnimation(transitionContext) 182 | case .dismiss: 183 | dismissAnimation(transitionContext) 184 | } 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Utils/Auto.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Auto.swift 3 | // ┌─┐ ┌───────┐ ┌───────┐ 4 | // │ │ │ ┌─────┘ │ ┌─────┘ 5 | // │ │ │ └─────┐ │ └─────┐ 6 | // │ │ │ ┌─────┘ │ ┌─────┘ 7 | // │ └─────┐│ └─────┐ │ └─────┐ 8 | // └───────┘└───────┘ └───────┘ 9 | // 10 | // Created by lee on 2018/11/2. 11 | // Copyright © 2018年 lee. All rights reserved. 12 | // 13 | 14 | import Foundation 15 | 16 | #if os(iOS) 17 | 18 | import UIKit 19 | 20 | public enum Auto { 21 | 22 | /// 设置转换闭包 23 | /// 24 | /// - Parameter conversion: 转换闭包 25 | public static func set(conversion: @escaping ((Double) -> Double)) { 26 | conversionClosure = conversion 27 | } 28 | 29 | /// 转换 用于数值的等比例计算 如需自定义可重新设置 30 | static var conversionClosure: ((Double) -> Double) = { (origin) in 31 | guard UIDevice.current.userInterfaceIdiom == .phone else { 32 | return origin 33 | } 34 | 35 | let base = 375.0 36 | let screenWidth = Double(UIScreen.main.bounds.width) 37 | let screenHeight = Double(UIScreen.main.bounds.height) 38 | let width = min(screenWidth, screenHeight) 39 | return (origin * (width / base)).rounded(places: 3) 40 | } 41 | } 42 | 43 | extension Auto { 44 | 45 | static func conversion(_ value: Double) -> Double { 46 | return conversionClosure(value) 47 | } 48 | } 49 | 50 | protocol AutoCalculationable { 51 | 52 | /// 自动计算 53 | /// 54 | /// - Returns: 结果 55 | func auto() -> Self 56 | } 57 | 58 | extension Double: AutoCalculationable { 59 | 60 | func auto() -> Double { 61 | return Auto.conversion(self) 62 | } 63 | } 64 | 65 | extension BinaryInteger { 66 | 67 | public func auto() -> Double { 68 | let temp = Double("\(self)") ?? 0 69 | return temp.auto() 70 | } 71 | public func auto() -> T where T : BinaryInteger { 72 | let temp = Double("\(self)") ?? 0 73 | return temp.auto() 74 | } 75 | public func auto() -> T where T : BinaryFloatingPoint { 76 | let temp = Double("\(self)") ?? 0 77 | return temp.auto() 78 | } 79 | } 80 | 81 | extension BinaryFloatingPoint { 82 | 83 | public func auto() -> Double { 84 | let temp = Double("\(self)") ?? 0 85 | return temp.auto() 86 | } 87 | public func auto() -> T where T : BinaryInteger { 88 | let temp = Double("\(self)") ?? 0 89 | return T(temp.auto()) 90 | } 91 | public func auto() -> T where T : BinaryFloatingPoint { 92 | let temp = Double("\(self)") ?? 0 93 | return T(temp.auto()) 94 | } 95 | } 96 | 97 | extension CGPoint: AutoCalculationable { 98 | 99 | public func auto() -> CGPoint { 100 | return CGPoint(x: x.auto(), y: y.auto()) 101 | } 102 | } 103 | 104 | extension CGSize: AutoCalculationable { 105 | 106 | public func auto() -> CGSize { 107 | return CGSize(width: width.auto(), height: height.auto()) 108 | } 109 | } 110 | 111 | extension CGRect: AutoCalculationable { 112 | 113 | public func auto() -> CGRect { 114 | return CGRect(origin: origin.auto(), size: size.auto()) 115 | } 116 | } 117 | 118 | extension CGVector: AutoCalculationable { 119 | 120 | public func auto() -> CGVector { 121 | return CGVector(dx: dx.auto(), dy: dy.auto()) 122 | } 123 | } 124 | 125 | extension UIOffset: AutoCalculationable { 126 | 127 | public func auto() -> UIOffset { 128 | return UIOffset(horizontal: horizontal.auto(), vertical: vertical.auto()) 129 | } 130 | } 131 | 132 | extension UIEdgeInsets: AutoCalculationable { 133 | 134 | public func auto() -> UIEdgeInsets { 135 | return UIEdgeInsets( 136 | top: top.auto(), 137 | left: left.auto(), 138 | bottom: bottom.auto(), 139 | right: right.auto() 140 | ) 141 | } 142 | } 143 | 144 | 145 | extension NSLayoutConstraint { 146 | 147 | @IBInspectable private var autoConstant: Bool { 148 | get { return false } 149 | set { 150 | guard newValue else { return } 151 | 152 | constant = constant.auto() 153 | } 154 | } 155 | } 156 | 157 | extension UIView { 158 | 159 | @IBInspectable private var autoCornerRadius: CGFloat { 160 | get { return layer.cornerRadius } 161 | set { 162 | let value = newValue.auto() 163 | layer.masksToBounds = true 164 | layer.cornerRadius = abs(CGFloat(Int(value * 100)) / 100) 165 | } 166 | } 167 | } 168 | 169 | extension UILabel { 170 | 171 | @IBInspectable private var autoFont: Bool { 172 | get { return false } 173 | set { 174 | guard newValue else { return } 175 | guard let text = attributedText?.mutableCopy() as? NSMutableAttributedString else { 176 | return 177 | } 178 | 179 | font = UIFont( 180 | name: font.fontName, 181 | size: font.pointSize.auto() 182 | ) 183 | attributedText = text.reset(font: { $0.auto() }) 184 | } 185 | } 186 | 187 | @IBInspectable private var autoLine: Bool { 188 | get { return false } 189 | set { 190 | guard newValue else { return } 191 | guard let text = attributedText else { return } 192 | 193 | attributedText = text.reset(line: { $0.auto() }) 194 | } 195 | } 196 | 197 | @IBInspectable private var autoShadowOffset: Bool { 198 | get { return false } 199 | set { 200 | guard newValue else { return } 201 | 202 | shadowOffset = shadowOffset.auto() 203 | } 204 | } 205 | } 206 | 207 | extension UITextView { 208 | 209 | @IBInspectable private var autoFont: Bool { 210 | get { return false } 211 | set { 212 | guard newValue else { return } 213 | guard let font = font else { return } 214 | 215 | self.font = UIFont( 216 | name: font.fontName, 217 | size: font.pointSize.auto() 218 | ) 219 | } 220 | } 221 | } 222 | 223 | extension UITextField { 224 | 225 | @IBInspectable private var autoFont: Bool { 226 | get { return false } 227 | set { 228 | guard newValue else { return } 229 | guard let font = font else { return } 230 | 231 | self.font = UIFont( 232 | name: font.fontName, 233 | size: font.pointSize.auto() 234 | ) 235 | } 236 | } 237 | } 238 | 239 | extension UIImageView { 240 | 241 | @IBInspectable private var autoImage: Bool { 242 | get { return false } 243 | set { 244 | guard newValue else { return } 245 | 246 | if let width = image?.size.width { 247 | image = image?.scaled(to: width.auto()) 248 | } 249 | if let width = highlightedImage?.size.width { 250 | highlightedImage = highlightedImage?.scaled(to: width.auto()) 251 | } 252 | } 253 | } 254 | } 255 | 256 | extension UIButton { 257 | 258 | @IBInspectable private var autoTitle: Bool { 259 | get { return false } 260 | set { 261 | guard newValue else { return } 262 | 263 | let states: [UIControl.State] = [ 264 | .normal, 265 | .highlighted, 266 | .selected, 267 | .disabled 268 | ] 269 | 270 | if 271 | let _ = title(for: state), 272 | let label = titleLabel, 273 | let font = label.font { 274 | label.font = UIFont( 275 | name: font.fontName, 276 | size: font.pointSize.auto() 277 | ) 278 | } 279 | 280 | let titles = states.enumerated().compactMap { 281 | (i, state) -> (Int, NSAttributedString)? in 282 | guard let t = attributedTitle(for: state) else { return nil } 283 | return (i, t) 284 | } 285 | titles.filtered(duplication: { $0.1 }).forEach { 286 | setAttributedTitle( 287 | $0.1.reset(font: { $0.auto() }), 288 | for: states[$0.0] 289 | ) 290 | } 291 | } 292 | } 293 | 294 | @IBInspectable private var autoImage: Bool { 295 | get { return false } 296 | set { 297 | guard newValue else { return } 298 | 299 | let states: [UIControl.State] = [ 300 | .normal, 301 | .highlighted, 302 | .selected, 303 | .disabled 304 | ] 305 | 306 | let images = states.enumerated().compactMap { 307 | (i, state) -> (Int, UIImage)? in 308 | guard let v = image(for: state) else { return nil } 309 | return (i, v) 310 | } 311 | images.filtered(duplication: { $0.1 }).forEach { 312 | setImage( 313 | $0.1.scaled(to: $0.1.size.width.auto()), 314 | for: states[$0.0] 315 | ) 316 | } 317 | 318 | let backgrounds = states.enumerated().compactMap { 319 | (i, state) -> (Int, UIImage)? in 320 | guard let v = backgroundImage(for: state) else { return nil } 321 | return (i, v) 322 | } 323 | backgrounds.filtered(duplication: { $0.1 }).forEach { 324 | setBackgroundImage( 325 | $0.1.scaled(to: $0.1.size.width.auto()), 326 | for: states[$0.0] 327 | ) 328 | } 329 | } 330 | } 331 | 332 | @IBInspectable private var autoTitleInsets: Bool { 333 | get { return false } 334 | set { 335 | guard newValue else { return } 336 | 337 | titleEdgeInsets = titleEdgeInsets.auto() 338 | } 339 | } 340 | 341 | @IBInspectable private var autoImageInsets: Bool { 342 | get { return false } 343 | set { 344 | guard newValue else { return } 345 | 346 | imageEdgeInsets = imageEdgeInsets.auto() 347 | } 348 | } 349 | 350 | @IBInspectable private var autoContentInsets: Bool { 351 | get { return false } 352 | set { 353 | guard newValue else { return } 354 | 355 | contentEdgeInsets = contentEdgeInsets.auto() 356 | } 357 | } 358 | } 359 | 360 | @available(iOS 9.0, *) 361 | extension UIStackView { 362 | 363 | @IBInspectable private var autoSpacing: Bool { 364 | get { return false } 365 | set { 366 | guard newValue else { return } 367 | 368 | spacing = spacing.auto() 369 | } 370 | } 371 | } 372 | 373 | fileprivate extension NSAttributedString { 374 | 375 | func reset(font size: (CGFloat) -> CGFloat) -> NSAttributedString { 376 | let string = NSMutableAttributedString(attributedString: self) 377 | enumerateAttributes( 378 | in: NSRange(location: 0, length: length), 379 | options: .longestEffectiveRangeNotRequired 380 | ) { (attributes, range, stop) in 381 | var temp = attributes 382 | if let font = attributes[.font] as? UIFont { 383 | temp[.font] = UIFont( 384 | name: font.fontName, 385 | size: size(font.pointSize) 386 | ) 387 | } 388 | string.setAttributes(temp, range: range) 389 | } 390 | return string 391 | } 392 | 393 | func reset(line spacing: (CGFloat) -> CGFloat) -> NSAttributedString { 394 | let string = NSMutableAttributedString(attributedString: self) 395 | enumerateAttributes( 396 | in: NSRange(location: 0, length: length), 397 | options: .longestEffectiveRangeNotRequired 398 | ) { (attributes, range, stop) in 399 | var temp = attributes 400 | if let paragraph = attributes[.paragraphStyle] as? NSMutableParagraphStyle { 401 | paragraph.lineSpacing = spacing(paragraph.lineSpacing) 402 | temp[.paragraphStyle] = paragraph 403 | } 404 | string.setAttributes(temp, range: range) 405 | } 406 | return string 407 | } 408 | } 409 | 410 | fileprivate extension UIImage { 411 | 412 | func scaled(to width: CGFloat, opaque: Bool = false) -> UIImage? { 413 | guard self.size.width > 0 else { 414 | return nil 415 | } 416 | 417 | let scale = width / self.size.width 418 | let size = CGSize(width: width, height: self.size.height * scale) 419 | UIGraphicsBeginImageContextWithOptions(size, false, 0) 420 | draw(in: CGRect(origin: .zero, size: size)) 421 | let new = UIGraphicsGetImageFromCurrentImageContext() 422 | UIGraphicsEndImageContext() 423 | return new 424 | } 425 | } 426 | 427 | fileprivate extension Array { 428 | 429 | func filtered(duplication closure: (Element) throws -> E) rethrows -> [Element] { 430 | return try reduce(into: [Element]()) { (result, e) in 431 | let contains = try result.contains { try closure($0) == closure(e) } 432 | result += contains ? [] : [e] 433 | } 434 | } 435 | } 436 | 437 | fileprivate extension Double { 438 | 439 | func rounded(places: Int) -> Double { 440 | let divisor = pow(10.0, Double(places)) 441 | return (self * divisor).rounded() / divisor 442 | } 443 | } 444 | 445 | #endif 446 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Utils/Inch.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Inch.swift 3 | // ┌─┐ ┌───────┐ ┌───────┐ 4 | // │ │ │ ┌─────┘ │ ┌─────┘ 5 | // │ │ │ └─────┐ │ └─────┐ 6 | // │ │ │ ┌─────┘ │ ┌─────┘ 7 | // │ └─────┐│ └─────┐ │ └─────┐ 8 | // └───────┘└───────┘ └───────┘ 9 | // 10 | // Created by lee on 2018/1/22. 11 | // Copyright © 2018年 lee. All rights reserved. 12 | // 13 | 14 | import Foundation 15 | 16 | #if os(iOS) 17 | 18 | import UIKit 19 | 20 | public enum Inch { 21 | typealias Number = CGFloat 22 | } 23 | 24 | extension Inch { 25 | 26 | public enum Phone: Int, CaseIterable { 27 | case unknown = -1 28 | case i35 29 | case i40 30 | case i47 31 | case i55 32 | case i58Full 33 | case i61Full 34 | case i65Full 35 | 36 | var width: Number { 37 | switch self { 38 | case .unknown: return 0 39 | case .i35: return 320 40 | case .i40: return 320 41 | case .i47: return 375 42 | case .i55: return 414 43 | case .i58Full: return 375 44 | case .i61Full: return 414 45 | case .i65Full: return 414 46 | } 47 | } 48 | 49 | var height: Number { 50 | switch self { 51 | case .unknown: return 0 52 | case .i35: return 480 53 | case .i40: return 568 54 | case .i47: return 667 55 | case .i55: return 736 56 | case .i58Full: return 812 57 | case .i61Full: return 896 58 | case .i65Full: return 896 59 | } 60 | } 61 | 62 | var scale: CGFloat { 63 | switch self { 64 | case .unknown: return 0 65 | case .i35: return 2 66 | case .i40: return 2 67 | case .i47: return 2 68 | case .i55: return 3 69 | case .i58Full: return 3 70 | case .i61Full: return 2 71 | case .i65Full: return 3 72 | } 73 | } 74 | 75 | private var size: CGSize { return CGSize(width: width, height: height) } 76 | private var native: CGSize { return CGSize(width: width * scale, height: height * scale) } 77 | 78 | public static func type(size: CGSize = UIScreen.main.bounds.size, 79 | scale: CGFloat = UIScreen.main.scale) -> Phone { 80 | let width = min(size.width, size.height) * scale 81 | let height = max(size.width, size.height) * scale 82 | let size = CGSize(width: width, height: height) 83 | 84 | switch size { 85 | case Phone.i35.native: return .i35 86 | case Phone.i40.native: return .i40 87 | case Phone.i47.native: return .i47 88 | case Phone.i55.native: return .i55 89 | case Phone.i58Full.native: return .i58Full 90 | case Phone.i61Full.native: return .i61Full 91 | case Phone.i65Full.native: return .i65Full 92 | default: return .unknown 93 | } 94 | } 95 | 96 | public static let current: Phone = type() 97 | } 98 | } 99 | 100 | extension Inch.Phone: Equatable { 101 | public static func == (lhs: Inch.Phone, rhs: Inch.Phone) -> Bool { 102 | return lhs.rawValue == rhs.rawValue 103 | } 104 | } 105 | 106 | extension Inch.Phone: Comparable { 107 | public static func < (lhs: Inch.Phone, rhs: Inch.Phone) -> Bool { 108 | return lhs.rawValue < rhs.rawValue 109 | } 110 | } 111 | 112 | extension Int: Inchable {} 113 | extension Bool: Inchable {} 114 | extension Float: Inchable {} 115 | extension Double: Inchable {} 116 | extension String: Inchable {} 117 | extension CGRect: Inchable {} 118 | extension CGSize: Inchable {} 119 | extension CGFloat: Inchable {} 120 | extension CGPoint: Inchable {} 121 | extension UIImage: Inchable {} 122 | extension UIColor: Inchable {} 123 | extension UIFont: Inchable {} 124 | extension UIEdgeInsets: Inchable {} 125 | 126 | public protocol Inchable { 127 | 128 | func i35(_ value: Self) -> Self 129 | func i40(_ value: Self) -> Self 130 | func i47(_ value: Self) -> Self 131 | func i55(_ value: Self) -> Self 132 | func i58full(_ value: Self) -> Self 133 | func i61full(_ value: Self) -> Self 134 | func i65full(_ value: Self) -> Self 135 | 136 | func w320(_ value: Self) -> Self 137 | func w375(_ value: Self) -> Self 138 | func w414(_ value: Self) -> Self 139 | } 140 | 141 | extension Inchable { 142 | 143 | public func i35(_ value: Self) -> Self { 144 | return matching(type: .i35, value) 145 | } 146 | public func i40(_ value: Self) -> Self { 147 | return matching(type: .i40, value) 148 | } 149 | public func i47(_ value: Self) -> Self { 150 | return matching(type: .i47, value) 151 | } 152 | public func i55(_ value: Self) -> Self { 153 | return matching(type: .i55, value) 154 | } 155 | public func i58full(_ value: Self) -> Self { 156 | return matching(type: .i58Full, value) 157 | } 158 | public func i61full(_ value: Self) -> Self { 159 | return matching(type: .i61Full, value) 160 | } 161 | public func i65full(_ value: Self) -> Self { 162 | return matching(type: .i65Full, value) 163 | } 164 | public func ifull(_ value: Self) -> Self { 165 | return matching([.i58Full, .i61Full, .i65Full], value) 166 | } 167 | 168 | public func w320(_ value: Self) -> Self { 169 | return matching(width: 320, value) 170 | } 171 | public func w375(_ value: Self) -> Self { 172 | return matching(width: 375, value) 173 | } 174 | public func w414(_ value: Self) -> Self { 175 | return matching(width: 414, value) 176 | } 177 | 178 | private func matching(type: Inch.Phone, _ value: Self) -> Self { 179 | return Inch.Phone.current == type ? value : self 180 | } 181 | private func matching(width: Inch.Number, _ value: Self) -> Self { 182 | return Inch.Phone.current.width == width ? value : self 183 | } 184 | 185 | private func matching(_ types: [Inch.Phone], _ value: Self) -> Self { 186 | return types.contains(.current) ? value : self 187 | } 188 | private func matching(_ range: Range, _ value: Self) -> Self { 189 | return range ~= .current ? value : self 190 | } 191 | private func matching(_ range: ClosedRange, _ value: Self) -> Self { 192 | return range ~= .current ? value : self 193 | } 194 | } 195 | 196 | #endif 197 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/Utils/StoryBoard.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StoryBoard.swift 3 | // LiveTrivia 4 | // 5 | // Created by 李响 on 2018/1/16. 6 | // Copyright © 2018年 LiveTrivia. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | enum StoryBoard: String { 13 | case main = "Main" 14 | 15 | var storyboard: UIStoryboard { 16 | return UIStoryboard(name: rawValue, bundle: nil) 17 | } 18 | 19 | func instance() -> T { 20 | return storyboard.instantiateViewController(withIdentifier: String(describing: T.self)) as! T 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/VerticalFullViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VerticalFullViewController.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class VerticalFullViewController: UIViewController { 12 | 13 | lazy var transition: Transition = { 14 | loadViewIfNeeded() 15 | $0.targetView = playerView 16 | $0.targetGravity = .resizeAspectFill 17 | return $0 18 | } ( VideoFullTransition() ) 19 | 20 | /// 详情控制器 持有 防止每次初始化新的 (根据需求调整即可) 21 | lazy var detailController: DetailViewController = .instance() 22 | 23 | @IBOutlet weak var playerView: PlayerView! 24 | @IBOutlet weak var backButton: UIButton! 25 | @IBOutlet weak var detailButton: UIButton! 26 | 27 | @IBOutlet weak var statusHeightConstraint: NSLayoutConstraint! 28 | 29 | override func viewDidLoad() { 30 | super.viewDidLoad() 31 | 32 | setup() 33 | setupLayout() 34 | } 35 | 36 | override func viewWillAppear(_ animated: Bool) { 37 | super.viewWillAppear(animated) 38 | // 解决横竖屏切换时 view异常 39 | view.frame = UIScreen.main.bounds 40 | } 41 | 42 | override func viewDidAppear(_ animated: Bool) { 43 | super.viewDidAppear(animated) 44 | // 显示控件 优化过渡效果 45 | showControls() 46 | } 47 | 48 | private func setup() { 49 | backButton.alpha = 0 50 | detailButton.alpha = 0 51 | } 52 | 53 | private func setupLayout() { 54 | statusHeightConstraint.constant = CGFloat(20).ifull(44) 55 | } 56 | 57 | private func gotoDetail() { 58 | if presentingViewController is DetailViewController { 59 | dismiss(animated: true) { } 60 | } else { 61 | let controller = detailController 62 | let transition = controller.transition as! VideoDetailTransition 63 | transition.sourceView = playerView 64 | transition.sourceGravity = .resizeAspectFill 65 | controller.type = .vertical 66 | controller.modalPresentationStyle = .fullScreen 67 | controller.transitioningDelegate = transition 68 | present(controller, animated: true) { } 69 | } 70 | } 71 | 72 | @IBAction func backAction(_ sender: Any) { 73 | dismiss(animated: true) { } 74 | } 75 | 76 | @IBAction func detailAction(_ sender: Any) { 77 | gotoDetail() 78 | } 79 | 80 | override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { 81 | super.present(viewControllerToPresent, animated: flag, completion: completion) 82 | 83 | hideControls() 84 | } 85 | 86 | override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { 87 | super.dismiss(animated: flag, completion: completion) 88 | 89 | hideControls() 90 | } 91 | 92 | override var shouldAutorotate: Bool { 93 | return false 94 | } 95 | 96 | override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 97 | return .portrait 98 | } 99 | 100 | override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { 101 | return .portrait 102 | } 103 | 104 | class func instance() -> Self { 105 | return StoryBoard.main.instance() 106 | } 107 | 108 | deinit { print("VerticalFullViewController deinit") } 109 | } 110 | 111 | extension VerticalFullViewController { 112 | 113 | /// 显示控件 114 | private func showControls() { 115 | UIView.beginAnimations("", context: nil) 116 | backButton.alpha = 1.0 117 | detailButton.alpha = 1.0 118 | UIView.commitAnimations() 119 | } 120 | 121 | /// 隐藏控件 122 | private func hideControls() { 123 | UIView.beginAnimations("", context: nil) 124 | backButton.alpha = 0 125 | detailButton.alpha = 0 126 | UIView.commitAnimations() 127 | } 128 | } 129 | 130 | extension VerticalFullViewController: VideoFullable { } 131 | extension VerticalFullViewController: TransitionTarget { } 132 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/View/PlayerView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PlayerView.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PlayerView: UIView { 12 | 13 | override func layoutSubviews() { 14 | super.layoutSubviews() 15 | 16 | if let animation = layer.animation(forKey: "bounds.size") { 17 | CATransaction.begin() 18 | CATransaction.setAnimationDuration(animation.duration) 19 | CATransaction.setAnimationTimingFunction(animation.timingFunction) 20 | layer.sublayers?.forEach({ $0.frame = bounds }) 21 | CATransaction.commit() 22 | } else { 23 | layer.sublayers?.forEach({ $0.frame = bounds }) 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/View/VideoCommentTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VideoCommentTableViewCell.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/22. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class VideoCommentTableViewCell: UITableViewCell { 12 | 13 | override func awakeFromNib() { 14 | super.awakeFromNib() 15 | // Initialization code 16 | } 17 | 18 | override func setSelected(_ selected: Bool, animated: Bool) { 19 | super.setSelected(selected, animated: animated) 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/View/VideoTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VideoTableViewCell.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol VideoTableViewCellDelegate: NSObjectProtocol { 12 | func fullH(view: UIView) 13 | func fullV(view: UIView) 14 | func detail(view: UIView, type: DetailType) 15 | } 16 | 17 | class VideoTableViewCell: UITableViewCell { 18 | 19 | weak var delegate: VideoTableViewCellDelegate? 20 | var indexPath: IndexPath? 21 | 22 | @IBOutlet weak var playerView: PlayerView! 23 | 24 | override func awakeFromNib() { 25 | super.awakeFromNib() 26 | } 27 | 28 | @IBAction func detailAction(_ sender: Any) { 29 | let type: DetailType = indexPath?.section == 1 ? .horizontal : .vertical 30 | delegate?.detail(view: playerView, type: type) 31 | } 32 | 33 | @IBAction func fullAction(_ sender: Any) { 34 | // 为了演示 第二条打开横屏 35 | if indexPath?.section == 1 { 36 | delegate?.fullH(view: playerView) 37 | } else { 38 | delegate?.fullV(view: playerView) 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // VideoTransitionDemo 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AVKit 11 | 12 | // 主要为了演示视频转场过渡 视频播放器简单带过 13 | let url = URL(string: "https://devstreaming-cdn.apple.com/videos/tutorials/20170912/201qy4t11tjpm/building_apps_for_iphone_x/hls_vod_mvp.m3u8")! 14 | let player = AVPlayer(playerItem: playerItem) 15 | let playerItem = AVPlayerItem(url: url) 16 | let playerLayer = AVPlayerLayer(player: player) 17 | 18 | class ViewController: UIViewController { 19 | 20 | @IBOutlet weak var tableView: UITableView! 21 | @IBOutlet weak var topConstraint: NSLayoutConstraint! 22 | 23 | override func viewDidLoad() { 24 | super.viewDidLoad() 25 | 26 | // 为了解决横竖屏切换时 SafeArea变动导致的布局问题 27 | // 这里所有的布局尽量不要使用SafeArea 28 | topConstraint.constant = CGFloat(20).ifull(44) 29 | 30 | player.play() 31 | } 32 | 33 | override func viewWillAppear(_ animated: Bool) { 34 | super.viewWillAppear(animated) 35 | // 解决横竖屏切换时 view异常 36 | view.frame = UIScreen.main.bounds 37 | } 38 | 39 | override var shouldAutorotate: Bool { 40 | return true 41 | } 42 | 43 | override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 44 | return .portrait 45 | } 46 | 47 | override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { 48 | return .portrait 49 | } 50 | } 51 | 52 | extension ViewController: UITableViewDelegate, UITableViewDataSource { 53 | 54 | func numberOfSections(in tableView: UITableView) -> Int { 55 | return 2 56 | } 57 | 58 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 59 | return 2 60 | } 61 | 62 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 63 | let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! VideoTableViewCell 64 | cell.delegate = self 65 | cell.indexPath = indexPath 66 | return cell 67 | } 68 | 69 | func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 70 | switch section { 71 | case 0: 72 | return "竖屏视频 - " 73 | case 1: 74 | return "横屏视频 - " 75 | default: 76 | return "" 77 | } 78 | } 79 | } 80 | 81 | extension ViewController: VideoTableViewCellDelegate { 82 | 83 | /// 跳转全屏(横屏) 84 | func fullH(view: UIView) { 85 | let controller = HorizontalFullViewController.instance() 86 | let transition = controller.transition as! VideoFullTransition 87 | transition.sourceView = view 88 | transition.sourceGravity = .resizeAspect 89 | controller.modalPresentationStyle = .fullScreen 90 | controller.transitioningDelegate = transition 91 | present(controller, animated: true) { } 92 | } 93 | 94 | /// 跳转全屏(竖屏) 95 | func fullV(view: UIView) { 96 | let controller = VerticalFullViewController.instance() 97 | let transition = controller.transition as! VideoFullTransition 98 | transition.sourceView = view 99 | transition.sourceGravity = .resizeAspect 100 | controller.modalPresentationStyle = .fullScreen 101 | controller.transitioningDelegate = transition 102 | present(controller, animated: true) { } 103 | } 104 | 105 | /// 跳转详情 106 | func detail(view: UIView, type: DetailType) { 107 | let controller = DetailViewController.instance() 108 | let transition = controller.transition as! VideoDetailTransition 109 | transition.sourceView = view 110 | transition.sourceGravity = .resizeAspect 111 | controller.type = type 112 | controller.modalPresentationStyle = .fullScreen 113 | controller.transitioningDelegate = transition 114 | present(controller, animated: true) { } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemoTests/VideoTransitionDemoTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VideoTransitionDemoTests.swift 3 | // VideoTransitionDemoTests 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import VideoTransitionDemo 11 | 12 | class VideoTransitionDemoTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemoUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /VideoTransitionDemo/VideoTransitionDemoUITests/VideoTransitionDemoUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VideoTransitionDemoUITests.swift 3 | // VideoTransitionDemoUITests 4 | // 5 | // Created by 李响 on 2018/5/18. 6 | // Copyright © 2018年 李响. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class VideoTransitionDemoUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------