dic*_*ala 0 iphone objective-c uiview ios
我有一个父视图控制器,并且有一个子视图(UIView)。
子视图(名为 xibSubView)称为其他自定义类(xib)文件。
当我单击父视图控制器时,子视图(UIView)将移动到触摸父视图控制器上的开始位置。
父视图控制器有
// UIViewcontroller.h file
.....
@property (weak, nonatomic) IBOutlet XibSubView *xibSubView;
.....
Run Code Online (Sandbox Code Playgroud)
以下代码位于父视图控制器.m中
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.subViewConstraint.constant = touchLeftScreenPoint.x ;
self.subViewConstraint.constant = touchLeftScreenPoint.y ;
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
Run Code Online (Sandbox Code Playgroud)
xib(subview-xibSubView) 代码具有相同的委托方法。
// The code is in the parent viewcontroller .m
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
Run Code Online (Sandbox Code Playgroud)
xibSubView 中有很多元素。
其中一个元素将移动到子视图(xibSubView)中的单击位置。
所以我想将父视图控制器触摸传递到 xibSubView 中。
并手动调用xibSubView中的touchBegan让元素运动。
所以我应该将父视图控制器触摸位置转换为子视图触摸位置。
子视图触摸x位置和y位置会减去viewcontroller的宽度和高度并手动调用touchbegan方法。
但我不知道如何改变触摸x,y值恢复触摸。
然后调用代码:
[self.xibSubView touchesBegan:touches withEvent:event];
Run Code Online (Sandbox Code Playgroud)
如何更改 NSSet 触摸 x,y 变量并恢复触摸。
非常感谢。
NSMutableArray *touchArray = [NSMutableArray new];
[touchArray addObject:[UITouch new]];
NSSet *touches = [[NSSet alloc] init];
[touches setByAddingObjectsFromArray:touchArray];
[self touchesBegan:touches withEvent:UIEventTypeTouches];
Run Code Online (Sandbox Code Playgroud)
迅速
let tArr = NSMutableArray()
tArr.add(UITouch())
let touch = NSSet()
touch.adding(tArr)
touchesBegan(touch as! Set<UITouch>, with: nil)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3801 次 |
最近记录: |