V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
IsaacYoung
V2EX  ›  iDev

新手请教如何处理动画过程中旋转屏幕

  •  
  •   IsaacYoung · 2020-06-26 14:33:16 +08:00 · 2378 次点击
    这是一个创建于 1390 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近学习 iOS 开发做一个 demo App,效果是类似发牌的动画,卡牌堆在左下角,点击发牌,会从卡牌堆取三张卡片,通过 UIViewPropertyAnimator 移动到指定位置,如果动画执行过程中旋转屏幕,卡牌的宽高和要移动到目标位置可能会发生改变,怎么处理这种场景呢
    1 条回复    2020-07-01 16:02:01 +08:00
    chipmuck
        1
    chipmuck  
       2020-07-01 16:02:01 +08:00
    可以重写 viewWillTransition(to:with:) 这个方法:

    1. size 参数表示旋转后的 CGSize 值;
    2. coordinator 可以调用 animate(alongsideTransition:completion:) 来调整旋转时和旋转后你所想要更新的 UI 布局。

    具体的文档地址参考:

    https://developer.apple.com/documentation/uikit/uicontentcontainer/1621466-viewwilltransition
    https://developer.apple.com/documentation/uikit/uiviewcontrollertransitioncoordinator/1619300-animate
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   958 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:46 · PVG 05:46 · LAX 14:46 · JFK 17:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.