ios - uiview touch move 获取uiview上的 anchor

标签 ios

我有一个 View ,当我点击它时,它会左右移动。我只得到 View 的点中心。我怎样才能在 anchor 上获得 uiview,因为无论我在哪里点击 View ,它都会移动。

这是我的代码:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 

{
    NSLog(@"touchesMoved called"); 

    UITouch *touch = [[event allTouches] anyObject];

    CGPoint touchpoint=[touch locationInView:self.view];  

    if ([touch view]==secondView)
    {
      secondView.center=touchpoint;
      [self animateFirstPoint:[touch view]];
    }
}

最佳答案

如果我没看错,您正在搜索 UIView 的定位点。

首先导入QuartzCore:

#import <QuartzCore/QuartzCore.h>

现在您可以使用 View 的 anchor 了:

secondView.layer.anchorPoint = touchpoint;

关于ios - uiview touch move 获取uiview上的 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11578776/

相关文章:

ios - 在 Xcode 升级后 Flutter iOS 构建失败错误并带有多个命令

ios - 根据动态文本设置 UITextView 的宽度和高度

ios - 我应该在哪里添加 CALayers 到 UITableViewCell?

ios - 每次单击 'more' 选项时导航回选项卡选项表

ios - 字符串中的 NSDate 显示一个月前的日期

iphone - 无序修改和访问参数

ios - 使用 Parse 保存 CLCircularRegion

ios - 使用 iOS Stringsdict 文件的显式复数字符串

ios - 如何在 Facebook iOS SDK 中发布或分享?

ios - 在 iPad3 上而不是在模拟器上运行应用程序时,我在变量上得到 nil。 swift 4