iPhone双滑解锁?
我想要一个适用于 iOS 的控件,它可以从左到右滑动,类似于滑动解锁,但也可以从右到左滑动。我想要一些与 Android 锁定屏幕上的控件非常相似的东西,从左向右滑动解锁,从右向左滑动静音。
这似乎最容易通过子类化
UISlider
来实现, 正确的?我需要两个滑块,还是只需要一个滑块?是否已经有任何开源版本?
想法
以下是该协议的一个想法:
@interface DoubleSlider : UISlider
typedef enum {
DoubleSliderDirectionLeftToRight,
DoubleSliderDirectionRightToLeft
} DoubleSliderDirection;
@end
@protocol DoubleSliderDelegate <NSObject>
@optional
- (void)doubleSlider:(DoubleSlider *)doubleSlider
didBeginSlidingWithDirection:(DoubleSliderDirection)direction;
- (void)doubleSlider:(DoubleSlider *)doubleSlider
didEndSlidingWithDirection:(DoubleSliderDirection)direction;
@end
相关
I want a control for iOS that slides left-to-right, similar to slide to unlock, but also slides right-to-left. I want something very similar to the control on Android's lock screen, where sliding left-to-right unlocks and sliding right-to-left silences.
It seems like this would be easiest to implement by subclassing
UISlider
, right? Would I need two sliders, or should I do it with just one?Are there already any open source versions of this?
Ideas
Here's an idea of what the protocol might look like:
@interface DoubleSlider : UISlider
typedef enum {
DoubleSliderDirectionLeftToRight,
DoubleSliderDirectionRightToLeft
} DoubleSliderDirection;
@end
@protocol DoubleSliderDelegate <NSObject>
@optional
- (void)doubleSlider:(DoubleSlider *)doubleSlider
didBeginSlidingWithDirection:(DoubleSliderDirection)direction;
- (void)doubleSlider:(DoubleSlider *)doubleSlider
didEndSlidingWithDirection:(DoubleSliderDirection)direction;
@end
Related
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想不出任何第三方版本。我不认为 UISlider 是一个好的起点。如果我是你,我会继承 UIScrollView 。
将其设置在屏幕底部,高度为 44 像素左右。将图像放置在滚动视图上的适当位置,就像您发布的图像一样。
然后,符合 UIScrollViewDelegate并实施scrollViewDidScroll: 方法来跟踪用户何时向左或向右滑动。在此方法中,检查 UIScrollView 的 contentOffset 属性。通过反复试验,您可以找出您认为滑动滚动视图应该触发您正在寻找的操作的确切内容偏移量。
例如,如果 contentOffset 为 50 意味着它适用于 DoubleSliderDirectionLeftToRight,则可以触发委托回调,然后使用 scrollRectToVisible:animated:
抱歉,我的答案冗长且 RTFM 风格,但我没有代码支持 这。这只是猜测,但我不明白为什么这个解决方案不起作用:)
I can't think of any third party versions for this. I don't feel that UISlider would be a good place to begin. If I were you, I would subclass a UIScrollView instead.
Set it up at the bottom of the screen to have a height of 44 pixels or so. Lay down the images at the appropriate positions on the scrollView like in the image you posted.
Then, conform to the UIScrollViewDelegate and implement the scrollViewDidScroll: method to track when the user slides it left or right. Inside this method, check the contentOffset property of the UIScrollView. By trial and error, you can find out the exact content offsets where you feel that sliding the scrollview should trigger the actions you're looking for.
For example, if the contentOffset being 50 means that it's for DoubleSliderDirectionLeftToRight, you can fire off the delegate callback and then have the scrollview 'jump back' to the original position by using scrollRectToVisible:animated:
Sorry for the long winded and RTFM-ish answer, but I have no code to support this. This is just speculation, but I don't see why this solution would not work :)