开发者

How has this view and control been done?

开发者 https://www.devze.com 2023-04-08 19:18 出处:网络
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 imag

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 开发者_StackOverflowand vanishes. Any ideas on how this might have been done?

How has this view and control 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 could be a simple UIView, added as subview, shown with bringSubviewToFront. What happens when you tap on the image again while the menu is shown?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号