如何实现此视图和控制? [英] How has this view and control been done?

查看:128
本文介绍了如何实现此视图和控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片附于下面。基本上它是流行的照片编辑应用程序Snapseed。当您在正在编辑的图像上触摸拖动时,表格(如视图)会在图像顶部显示动画,其中的选项如下图所示。最整洁的部分是,它从屏幕上删除手指消失,你执行从下面的5个选项之一,如视图中的选择继续触摸拖动在图像上的向上或向下方向拖动之后使菜单出现。一旦选择,它将选择传递回父母并消失。任何想法如何这可能已经做了?



解决方案

带有按钮的视图可能是隐藏的,直到图像的视图检测到触摸,然后执行 touchesBegan:withEvent: / strong>方法,它是UIResponder类的一部分。大多数视图子类UIResponder,所以这是一个内置的方法,与 touchesEnded:withEvent:。当touchesEnded:withEvent:执行时,按钮视图被关闭。 (它要么立即隐藏,要么动画alpha值直到消失。)






更多信息



这里是Keith Lazuka从kal日历的一些代码。此代码查看触摸结束的位置,以确定日历上的tile是什么。我想在这里可以使用相同的东西来确定在你的示例中选择了哪个按钮。

   - (void)touchesBegan :(NSSet *)touches withEvent:(UIEvent *)event 
{
[self receivedTouches:touches withEvent:event];
}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self receivedTouches:touches withEvent :事件];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
UIView * hitView = [self hitTest:location withEvent:event];

// [self receivedTouches:touches withEvent:event];

if([hitView isKindOfClass:[KalTileView class]]){
KalTileView * tile =(KalTileView *)hitView;

if(tile.belongsToAdjacentMonth){
if([tile.date compare:[KalDate dateFromNSDate:logic.baseDate]] == NSOrderedDescending){
[delegate showFollowingMonth];
} else {
[delegate showPreviousMonth];
}
self.selectedTile = [frontMonthView tileForDate:tile.date];
} else {
//self.selectedTile = tile;
}
}
self.highlightedTile = nil;
}

这里的关键在于touchesEnded方法的前三行代码。



hitTest:withEvent:是一个UIView的实例方法,它根据触摸结束发生的点位置,告诉您在touchesEnded事件触发时触发了哪个视图。 / p>

正如你可以在这个示例代码中看到的,它返回一个UIView实例(或子类化UIView的东西)。一旦您知道哪个视图被识别,代码可以写入采取所需的操作。


The image is attached below. Basically it is the popular photo editing app Snapseed. When you touch drag on an image that is being edited a table like view animates in to visibility on top of the image with its options as seen below in the image. The neatest part is that it vanishes on removing the finger from the screen and you perform the selection from one of the 5 options below in that table like view by continuing to touch drag in the upward or downward direction immediately after touch dragging on the image to make the menu appear. Once selection is made, it passes back the selection to the parent and vanishes. Any ideas on how this might have been done?

解决方案

The view with the buttons is probably hidden until the view with the image detects a touch, whereupon it executes the touchesBegan:withEvent: method, which is part of the UIResponder class. Most views subclass UIResponder, so this is a built-in method, along with touchesEnded:withEvent:. When touchesEnded:withEvent: executes, the button view is dismissed. (It either hides immediately or it animates the alpha value until is disappears.)


More info

Here is some code from the kal Calendar by Keith Lazuka. This code looks at the position where the touch ended to determine what "tile" on the calendar is hit. I suppose the same thing could be used here to determine which "button" is selected in your example.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self receivedTouches:touches withEvent:event];
}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self receivedTouches:touches withEvent:event];
}

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
 {
 UITouch *touch = [touches anyObject];
 CGPoint location = [touch locationInView:self];
 UIView *hitView = [self hitTest:location withEvent:event];

 //[self receivedTouches:touches withEvent:event];

 if ([hitView isKindOfClass:[KalTileView class]]) {
 KalTileView *tile = (KalTileView*)hitView;

 if (tile.belongsToAdjacentMonth) {
 if ([tile.date compare:[KalDate dateFromNSDate:logic.baseDate]] == NSOrderedDescending) {
 [delegate showFollowingMonth];
 } else {
 [delegate showPreviousMonth];
 }
 self.selectedTile = [frontMonthView tileForDate:tile.date];
 } else {
 //self.selectedTile = tile;
 }
 }
 self.highlightedTile = nil;
 }

The key to this is in the first three lines of code in the touchesEnded method.

hitTest:withEvent: is an instance method of UIView that tells you which view was hit when the touchesEnded event fires, based on the point location where the touches ended occurs.

As you can see in this example code, it does return a UIView instance (or something subclassing UIView). Once you know which view was identified, to code can be written to take the desired action.

这篇关于如何实现此视图和控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆