【发布时间】:2017-11-25 20:57:00
【问题描述】:
我正在为 Gestrue Recognizer 工作,它有许多 UIView 用于在视图中进行旋转、捏合和平移操作。 我的问题是当我触摸时如何使我的 UIView 中的一个bringSubviewToFront,例如,like my photo,我希望在触摸时将绿色的一个带到前面。 (所以蓝色变成绿色的后面)
每个 UIView 都是从我的 NoteView 类初始化的
NoteView * noteView = [[NoteView alloc]initWithFrame:CGRectMake(50, 50, 150, 150)];
[self setGesture:noteView];
[self.view addSubview:noteView];
TouchsBegan 我就是这样工作的
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.note = [NoteView new];
UITouch * touch = [touches anyObject];
if (touch.view == self.note) {
[self.view bringSubviewToFront:self.note];
}}
【问题讨论】:
-
if (CGRectIntersectsRect(someView.frame, otherView.frame){[self.view bringSubViewToFront:oneOfTheView];}? -
在您的 touchesBegan:withEvent: 方法中,您要做的第一件事是创建一个新的 NoteView 并将其分配给一个 note 属性。 if (touch.view == self.note) 永远不会为真(触摸不能包含新的笔记视图,因为您刚刚创建了它),因此 if 语句范围内的代码将永远不会被执行。
-
你指出我的错误!你能告诉我如何获得我接触到的当前视图吗?谢谢!
标签: ios objective-c uigesturerecognizer touch-event bringtofront