![](/img/trans.png)
[英]how to add on touch and detect UIImageView on view so i could move it around and not adding one on top of it?
[英]How to move the particular UIImageview to top of the view?
我在單擊按鈕時創建UIImageview。
這是我的代碼:
_imgfull.userInteractionEnabled=YES;
_imgfull.clipsToBounds = YES;
//this all for image positioned
imgpositioned=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,500,500)];
imgpositioned.userInteractionEnabled=YES;
imgpositioned.tag=tag;
tag++;
if(tag==1)
{
imgpositioned.backgroundColor =[UIColor redColor];
}
else
{
imgpositioned.backgroundColor =[UIColor greenColor];
}
//pinch gesture
UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(Pinchforimage:)];
pinch.delegate=self;
[imgpositioned addGestureRecognizer:pinch];
// create and configure the rotation gesture
UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureDetected:)];
[rotationGestureRecognizer setDelegate:self];
[imgpositioned addGestureRecognizer:rotationGestureRecognizer];
// pan gesture
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureDetected:)];
[panGestureRecognizer setDelegate:self];
[imgpositioned addGestureRecognizer:panGestureRecognizer];
//long press gesture
UILongPressGestureRecognizer *longpress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpress:)];
[longpress setDelegate:self];
[imgpositioned addGestureRecognizer:longpress];
[_imgfull addSubview:imgpositioned];
這是我的長按手勢方法
[![-(void)longpress:(UILongPressGestureRecognizer *)longg
{
NSLog(@"gesture recogniser long press obtained ==%d",\[longg.view tag\]);
UIGestureRecognizerState state =\[longg state\];
if(state ==UIGestureRecognizerStateBegan ||state ==UIGestureRecognizerStateChanged)
{
\[imgpositioned superview\];
}
}
當用戶長按UIImageview時,我想將UIImageview移到上方,例如,如果用戶長按紅色UIImageview,則它必須位於綠色imageview的上方:)
可能幫助我的朋友:
使用此代碼[_imgfull bringSubviewToFront:longg.view];
在-(void)longpress:(UILongPressGestureRecognizer *)longg
方法
-(void)longpress:(UILongPressGestureRecognizer *)longg
{
UIGestureRecognizerState state =[longg state];
if(state ==UIGestureRecognizerStateBegan ||state ==UIGestureRecognizerStateChanged)
{
int temptag=[longg.view tag];
UIImageView *views=(UIImageView *)arrimgstore[temptag];
NSLog(@"got it to super view %@",views);
[_imgfull bringSubviewToFront:views];
}
}
終於我完成了工作,
注意事項:
我將UIImageview存儲在NSMutable數組中,然后使用手勢視圖標簽,將那些特定的UIImageview放在最前面:)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.