ios - 像 Instagram 登录一样更改渐变背景

标签 ios swift swift3 gradient

如何像 Instagram 登录一样改变渐变背景?

在 Android 中你可以这样做 this :

在 Swift 中有类似的方法吗?

最佳答案

如果你想用动画不断改变 View 的背景颜色,你可以这样设置。

var colors: [UIColor] = [.red, .blue, .green]

func startAnimation(index: Int) {
    UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
        self.view.backgroundColor = self.colors[index]
        }) { (finished) in
            var currentIndex = index + 1
            if currentIndex == self.colors.count { currentIndex = 0 }
            self.startAnimation(index: currentIndex)
    }
}

并使用索引 0 调用此函数。

self.startAnimation(index: 0)

关于ios - 像 Instagram 登录一样更改渐变背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40229702/

相关文章:

IOS CoreData,使用哪个 NSManagedObjectContextConcurrencyType,为什么?

ios - 使用 RxSwift 将 UITextField 绑定(bind)到 ViewModel

swift - 用 * 屏蔽名字和姓氏字符串

swift - Swift3 中的 Levenshtein 距离

ios - UILongPressGestureRecognizer 使用选择器传递参数

ios - 当我在 TabBarController 中切换 View 时,ScrollView 停止滚动,如何解决?

ios - 如何在 Swift 中合并和格式化数组? (X 和 Y 坐标数组)

ios - 如何在 RxSwift 中使用数据源和委托(delegate)方法

ios - FBSDK 检查用户是否已经授权应用程序 Swift

ios - 使用 Swift 在 iOS UI 中显示音乐 Unicode 符号