HapticButton

所属分类:iPhone/iOS
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2017-11-29 18:20:31
上 传 者sh-1993
说明:  基于3D Touch压力触发的按钮,类似于iOS 11控制中心。
(A button that is triggered based on the 3D Touch pressure, similar to the iOS 11 control center.)

文件列表:
.swift-version (4, 2017-11-29)
Example/ (0, 2017-11-29)
Example/HapticButton.xcodeproj/ (0, 2017-11-29)
Example/HapticButton.xcodeproj/project.pbxproj (17467, 2017-11-29)
Example/HapticButton.xcodeproj/project.xcworkspace/ (0, 2017-11-29)
Example/HapticButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata (157, 2017-11-29)
Example/HapticButton.xcodeproj/xcshareddata/ (0, 2017-11-29)
Example/HapticButton.xcodeproj/xcshareddata/xcschemes/ (0, 2017-11-29)
Example/HapticButton.xcodeproj/xcshareddata/xcschemes/HapticButton-Example.xcscheme (4476, 2017-11-29)
Example/HapticButton.xcworkspace/ (0, 2017-11-29)
Example/HapticButton.xcworkspace/contents.xcworkspacedata (230, 2017-11-29)
Example/HapticButton/ (0, 2017-11-29)
Example/HapticButton/AppDelegate.swift (2186, 2017-11-29)
Example/HapticButton/Base.lproj/ (0, 2017-11-29)
Example/HapticButton/Base.lproj/LaunchScreen.xib (3953, 2017-11-29)
Example/HapticButton/Base.lproj/Main.storyboard (12479, 2017-11-29)
Example/HapticButton/Images.xcassets/ (0, 2017-11-29)
Example/HapticButton/Images.xcassets/AppIcon.appiconset/ (0, 2017-11-29)
Example/HapticButton/Images.xcassets/AppIcon.appiconset/Contents.json (753, 2017-11-29)
Example/HapticButton/Images.xcassets/Contents.json (62, 2017-11-29)
Example/HapticButton/Images.xcassets/berlin.imageset/ (0, 2017-11-29)
Example/HapticButton/Images.xcassets/berlin.imageset/Contents.json (303, 2017-11-29)
Example/HapticButton/Images.xcassets/berlin.imageset/berlin.jpg (1291330, 2017-11-29)
Example/HapticButton/Images.xcassets/swift.imageset/ (0, 2017-11-29)
Example/HapticButton/Images.xcassets/swift.imageset/Contents.json (302, 2017-11-29)
Example/HapticButton/Images.xcassets/swift.imageset/swift.png (11595, 2017-11-29)
Example/HapticButton/Info.plist (1149, 2017-11-29)
Example/HapticButton/ViewController.swift (1467, 2017-11-29)
Example/Podfile (164, 2017-11-29)
Example/Podfile.lock (280, 2017-11-29)
Example/Pods/ (0, 2017-11-29)
Example/Pods/Local Podspecs/ (0, 2017-11-29)
Example/Pods/Local Podspecs/HapticButton.podspec.json (552, 2017-11-29)
Example/Pods/Manifest.lock (280, 2017-11-29)
Example/Pods/Pods.xcodeproj/ (0, 2017-11-29)
Example/Pods/Pods.xcodeproj/project.pbxproj (35212, 2017-11-29)
Example/Pods/Pods.xcodeproj/xcshareddata/ (0, 2017-11-29)
Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/ (0, 2017-11-29)
... ...

buddybuild Carthage License Platform Twitter: @BalestraPatrick

# HapticButton ## Description `HapticButton` replicates the behavior of the buttons in the iOS 10 and 11 Control Center as well as in the Home app. A device with 3D Touch is required to fully experience the haptic feedback on supported devices. It is implemented as a subclass of `UIControl`, so feel free to further customize it to your needs. The user is required to press the button and activate 3D Touch with a minimum pressure threshold (you can specify the minimum value to trigger the button via the `feedbackThreshold` property). This allows for a cool interaction that gives a haptic feedback to the user when the button is triggered. For the best experience, install the example on a device. The example project shows how to set up `HapticButton` in a few different ways. - Create a button with a `UILabel`. Use the `HapticButtonDelegate` to be notified when the button is triggered. ```swift @IBOutlet weak var button: HapticButton! button.mode = .label(text: "Hello! ") // Use the delegate method to be notified when the button is pressed. button.delegate = self ``` - Create a button with a `UIImageView` and a blur background. Use the standard `UIControl` event to subscribe to the touch up inside event. ```swift let blurButton = HapticButton(mode: .image(image: #imageLiteral(resourceName: "swift"))) blurButton.addBlurView(style: .light) // Add custom target selector to the touch up inside event. blurButton.addTarget(self, action: #selector(blurButtonPressed(_:)), for: .touchUpInside) ``` - Create a button with a customized `UILabel` and dark blur background. Subcribe to the button events through a closure. ```swift let blurButton = HapticButton(mode: .label(text: "Hello Blur!")) darkBlurButton.textLabel.textColor = .white darkBlurButton.addBlurView(style: .dark) // Pass closure to be invoked when the button is pressed. darkBlurButton.onPressed = { print("Dark blur button pressed.") } ``` ## Customizations These are the public properties that allow you to customize the control. In case you are thinking to modify `HapticButton` even further, consider creating a [Pull Request](https://github.com/BalestraPatrick/HapticButton/compare)! ```swift public weak var delegate: HapticButtonDelegate? /// The closure invoked when the button is pressed. public var onPressed: Callback? /// The minimum pressure that the button press has to receive in order to trigger the related haptic feedback. The value has to be between 0 and 1 and the default is 0.25. public var feedbackThreshold = 0.25 /// If the button is in mode `label`, this `UILabel` is part of the button hierarchy. Modify this object directly for more customizations on the displayed text. public lazy var textLabel: UILabel /// If the button is in mode `image`, this `UIImageView` is part of the button hierarchy. Modify this object directly for more customizations on the displayed image. public lazy var imageView: UIImageView /// The current mode of the button. public var mode = HapticButtonMode.label(text: "Title") ``` ## Requirements iOS 10.0 and Swift 3.2 are required. If you are using Swift 4, please use the [swift4 branch](https://github.com/BalestraPatrick/HapticButton/tree/swift4). ## Installation `HapticButton` is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your `Podfile`: ```ruby pod "HapticButton" ``` You can also use [Carthage](https://github.com/Carthage/Carthage) if you prefer. Add this line to your `Cartfile`. ```ruby github "BalestraPatrick/HapticButton" ``` ## Author I'm [Patrick Balestra](http://www.patrickbalestra.com). Email: [me@patrickbalestra.com](mailto:me@patrickbalestra.com) Twitter: [@BalestraPatrick](http://twitter.com/BalestraPatrick). ## License `HapticButton` is available under the MIT license. See the [LICENSE](LICENSE) file for more info.

近期下载者

相关文件


收藏者