mirror of
https://github.com/zhigang1992/RxSwift.git
synced 2026-06-12 00:54:34 +08:00
Conflicts: RxCocoa/Common/Observables/NSNotificationCenter+Rx.swift RxCocoa/OSX/NSImageView+Rx.swift RxCocoa/iOS/UICollectionView+Rx.swift RxCocoa/iOS/UIControl+Rx.swift RxCocoa/iOS/UIImageView+Rx.swift RxCocoa/iOS/UILabel+Rx.swift RxCocoa/iOS/UITableView+Rx.swift RxExample/RxDataSources/DataSources+Rx/UISectionedViewType+RxAnimatedDataSource.swift RxExample/RxExample/Examples/APIWrappers/APIWrappersViewController.swift RxExample/RxExample/Examples/GitHubSearchRepositories/GitHubSearchRepositoriesViewController.swift RxExample/RxExample/Examples/GitHubSignup/UsingDriver/GitHubSignupViewController2.swift RxExample/RxExample/Examples/GitHubSignup/UsingVanillaObservables/GitHubSignupViewController1.swift RxExample/RxExample/Examples/ImagePicker/UIImagePickerController+RxCreate.swift RxExample/RxExample/Examples/OSX simple example/IntroductionExampleViewController.swift RxExample/RxExample/Examples/SimpleTableViewExample/SimpleTableViewExampleViewController.swift RxExample/RxExample/Examples/SimpleTableViewExampleSectioned/SimpleTableViewExampleSectionedViewController.swift RxExample/RxExample/Examples/SimpleValidation/SimpleValidationViewController.swift RxExample/RxExample/Examples/TableViewPartialUpdates/PartialUpdatesViewController.swift RxExample/RxExample/Examples/TableViewWithEditingCommands/TableViewWithEditingCommandsViewController.swift RxExample/RxExample/Examples/WikipediaImageSearch/Views/WikipediaSearchCell.swift RxExample/RxExample/Examples/WikipediaImageSearch/Views/WikipediaSearchViewController.swift Tests/RxCocoaTests/DelegateProxyTest.swift Tests/RxCocoaTests/KVOObservableTests.swift Tests/RxCocoaTests/RxTest+Controls.swift Tests/RxCocoaTests/UICollectionView+RxTests.swift Tests/RxCocoaTests/UIScrollView+RxTests.swift Tests/RxCocoaTests/UITableView+RxTests.swift
75 lines
2.4 KiB
Swift
75 lines
2.4 KiB
Swift
//
|
|
// UIImageView+Rx.swift
|
|
// RxCocoa
|
|
//
|
|
// Created by Krunoslav Zaher on 4/1/15.
|
|
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
|
//
|
|
|
|
#if os(iOS) || os(tvOS)
|
|
|
|
import Foundation
|
|
#if !RX_NO_MODULE
|
|
import RxSwift
|
|
#endif
|
|
import UIKit
|
|
|
|
extension Reactive where Base: UIImageView {
|
|
|
|
/**
|
|
Bindable sink for `image` property.
|
|
*/
|
|
public var image: AnyObserver<UIImage?> {
|
|
return image(transitionType: nil)
|
|
}
|
|
|
|
/**
|
|
Bindable sink for `image` property.
|
|
|
|
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
|
*/
|
|
@available(*, deprecated, renamed: "image(transitionType:)")
|
|
public func imageAnimated(_ transitionType: String?) -> AnyObserver<UIImage?> {
|
|
return UIBindingObserver(UIElement: base) { imageView, image in
|
|
if let transitionType = transitionType {
|
|
if image != nil {
|
|
let transition = CATransition()
|
|
transition.duration = 0.25
|
|
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
|
transition.type = transitionType
|
|
imageView.layer.add(transition, forKey: kCATransition)
|
|
}
|
|
}
|
|
else {
|
|
imageView.layer.removeAllAnimations()
|
|
}
|
|
imageView.image = image
|
|
}.asObserver()
|
|
}
|
|
|
|
/**
|
|
Bindable sink for `image` property.
|
|
|
|
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
|
*/
|
|
public func image(transitionType: String? = nil) -> AnyObserver<UIImage?> {
|
|
return UIBindingObserver(UIElement: base) { imageView, image in
|
|
if let transitionType = transitionType {
|
|
if image != nil {
|
|
let transition = CATransition()
|
|
transition.duration = 0.25
|
|
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
|
transition.type = transitionType
|
|
imageView.layer.add(transition, forKey: kCATransition)
|
|
}
|
|
}
|
|
else {
|
|
imageView.layer.removeAllAnimations()
|
|
}
|
|
imageView.image = image
|
|
}.asObserver()
|
|
}
|
|
}
|
|
|
|
#endif
|