简体   繁体   English

触摸并拖动iPhone中的多个控件

[英]touch and drag multiple controls in iphone

I want to select multiple views in an interface and drag them together. 我想在一个界面中选择多个视图并将它们拖动到一起。 How can I implement this in xcode. 我如何在xcode中实现这一点。

For example i have some image views in a view then i want to select them by drawing a rectangle. 例如,我在视图中有一些图像视图,然后我想通过绘制矩形来选择它们。 then move them by dragging them. 然后拖动它们来移动它们。

Can anybody help me. 有谁能够帮助我。 Thanks in advance 提前致谢

Try this code 试试这个代码

#import "TouchView.h"


//TouchView.h

#import <Foundation/Foundation.h>
#import "TouchViewDelegate.h"

@interface TouchView : UIView {
    id <TouchViewDelegate>  delegate;
}
@property (retain) id delegate;
@end

//TouchView.m

@implementation TouchView
@synthesize delegate;

-(id) initWithFrame:(CGRect)frame
{
    self.userInteractionEnabled = YES;
    return self;
}
-(id) initWithCoder:(NSCoder *)aDecoder
{
    self.userInteractionEnabled = YES;
    return self;
}
-(void) awakeFromNib
{
    self.userInteractionEnabled = YES;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [delegate touchDown:self];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [delegate touchUp:self];
}
@end

//TouchViewDelegate.h
#import <UIKit/UIKit.h>


@protocol TouchViewDelegate
-(void) touchDown:(id) sender;
-(void) touchUp:(id)sender;
@end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM