我有两个imageViews imageView1和imageView2。我已经给了gestureRecognizer来移动这两个图像。现在的问题是,当我第一次移动imageView靠近第二个图像时,只显示第二个图像视图。但是当我把第一个imageView放在另一个图像上时,第一个imageView应该显示在第二个imageView上,这是不会发生的。可以请任何人告诉我第一个imageView如何在另一个imageView的顶部获取视图。区分两个ImageViews
1
A
回答
1
为什么不使用类似的东西来拖动你的UIImageView?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor yellowColor];
test1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
test1.backgroundColor = [UIColor whiteColor];
test1.userInteractionEnabled = YES;
test1.clipToBounds = YES;
[self.view addSubview:test1];
test2 = [[UIImageView alloc] initWithFrame:CGRectMake(400, 400, 100, 100)];
test2.backgroundColor = [UIColor whiteColor];
test2.userInteractionEnabled = YES;
test2.clipToBounds = YES;
[self.view addSubview:test2];
}
CGPoint startLocation;
float diffX;
float diffY;
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if([touch view] == test1)
{
startLocation = [touch locationInView:self.view];
[self.view bringSubviewToFront:test1];
}
if([touch view] == test2)
{
startLocation = [touch locationInView:self.view];
[self.view bringSubviewToFront:test2];
}
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
if([touch view] == test1)
{
CGPoint location = [touch locationInView:self.view];
diffX = location.x - startLocation.x;
diffY = location.y - startLocation.y;
test1.frame = CGRectMake(test1.frame.origin.x + diffX, test1.frame.origin.y + diffY, test1.frame.size.width, test1.frame.size.height);
startLocation = test1.frame.origin;
}
if([touch view] == test2)
{
CGPoint location = [touch locationInView:self.view];
diffX = location.x - startLocation.x;
diffY = location.y - startLocation.y;
test2.frame = CGRectMake(test2.frame.origin.x + diffX, test2.frame.origin.y + diffY, test2.frame.size.width, test2.frame.size.height);
startLocation = test2.frame.origin;
}
}
// --- 编辑 --- // 补充:在viewDidLoad中cliptobounds
2
您可以使用UIView
方法bringSubviewToFront:
,并通过UIImageView
您想显示在顶部。
相关问题
- 1. Android - 两个ImageViews并排
- 2. 如何比较两个ImageViews?
- 3. Android中两个重叠的ImageViews
- 4. 淡入淡出两个imageviews重叠
- 5. 如何区分两个表
- 6. saveAsParquetFile失败两个分区,并没有分区
- 7. 一个tapReRecognizer几个imageViews
- 8. 如何区分两个Linux时间戳
- 9. 区分两个数组索引?
- 10. 区分两个连接表AR
- 11. 使用Swift区分两个Xcode目标
- 12. Xpath区分同名的两个属性
- 13. 如何区分两个本地通知
- 14. 将直方图分成两个区域
- 15. 如何区分两个WhatsApp消息?
- 16. 如何在两个StartActivityFor结果区分()
- 17. 在nowjs中区分两个客户端
- 18. C:两个阵列的分区
- 19. 如何区分两个相撞的圆?
- 20. 如何区分两个日期,包括两个日期?
- 21. 显示多个ImageViews iPad
- 22. 在Oracle中没有拆分的前两个连续分区的分区
- 23. Android。两个imageViews,完美地适合屏幕
- 24. Android:可以将相同的位图设置为两个ImageViews吗?
- 25. 在Android中ImageViews之间优化分页?
- 26. 缩放ImageViews更高分辨率手机
- 27. 计数分区两侧ReQL
- 28. 如何区分Eclipse中相同文件的两个区域
- 29. 这两个分区函数之间的区别
- 30. 如何区分Python中两个词典的区别?
据工作绝对没问题,但是当涉及第二ImageView的附近是没有限。 –
是否设置了clipToBounds(BOOL)属性? –
是的,我已经把它设置为是在触动移动method.But仍然我有同样的问题。 –