目前我是这么做的:
- (void )loadView
{
self.view = [UIView new];
UIView *shareView = [UIView new];
[self.view addSubview:shareView];
shareView.backgroundColor = [UIColor colorWithRGBA:0xEEEEEEFF];
shareView.userInteractionEnabled = YES;
UITapGestureRecognizer *gestureForShare = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector (shareViewClicked:)];
gestureForShare.numberOfTapsRequired = 1;
[shareView addGestureRecognizer:gestureForShare];
}
- (void )shareViewClicked:(UITapGestureRecognizer *)gestureRecognizer
{
gestureRecognizer.view.backgroundColor = [UIColor colorWithRGBA:0xDDDDDDFF];
// 背景变暗持续 0.2s 后变回来
dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(0.2 * NSEC_PER_SEC )), dispatch_get_main_queue (), ^{
gestureRecognizer.view.backgroundColor = [UIColor colorWithRGBA:0xEEEEEEFF];
});
}
效果虽然实现了,但总感觉别扭,不知道大家是怎样做的...请教下。
1
hustlzp OP 按这种思路,如果需要再加上长按时背景变色的效果,那还得加上 longPressGesture ,然后根据 gesture 的状态进行背景色改变,感觉有点麻烦。
|
2
hustlzp OP 或者 subclass UIControl ,然后在 beginTrackingWithTouch 和 endTrackingWithTouch 中进行背景色改变?
|
3
wanganjun 2015-09-05 22:59:31 +08:00 via iPhone
感觉别扭可能是因为颜色变化太突然了吧,颜色逐渐变化的话,效果应该回好不少
|
5
wanganjun 2015-09-05 23:32:20 +08:00 via iPhone
原来咱们说的不是同一个东西
|
6
onevcat 2015-09-05 23:42:00 +08:00
touchesBegan , touchesEnded
|
7
fghfjujiber 2015-09-05 23:49:49 +08:00
用 touchesBegin: / touchesEnded: / touchesCanceled 会不会好些?
|
9
hustlzp OP @fghfjujiber 已经用上了, THX !
|
10
kobe1941 2015-09-06 11:29:04 +08:00
比如,短暂点一下背景变为灰色, 0.2 秒后恢复最初颜色,长按时背景变为红色,手指离开颜色恢复。
但是怎么区分用户是短暂点一下还是长按呢? |
11
chmlai 2015-09-06 11:51:30 +08:00
Gesture 明显比 touchBegan/Ended 好.
|