【问题标题】:Making draggable button in objective C在目标C中制作可拖动按钮
【发布时间】:2011-06-29 04:10:37
【问题描述】:

我正在尝试使用 UITouch 迁移到 UIImageViews。 我有 2 个 imageViews 说 image1 和 image2。我在 .h 文件中将这些声明为 UIIMageView *image1; UIImageView *image2;

现在在 touchesBegan 方法中,要拖动一个 imageView,我使用 if 条件如下

 if([touch view] = image1){
    image1.center = location;
 } 
 else if([touch view] = image2){
    image2.center = location;
 }

位置是 CGPoint。

使用此代码,当我构建 n 运行程序时,两个图像相互重叠并一起移动。 我想单独移动它们。

请提供一些帮助或任何错误...

【问题讨论】:

    标签: objective-c ios4 uibutton uitouch


    【解决方案1】:

    您的if 语句设置 [touch view] 使用=。如果你想测试是否相等,那么你必须使用isEqual:,这是NSObject 的表达方式==

     if([[touch view] isEqual:image1]){
        image1.center = location;
     } 
     else if([[touch view] isEqual:image2]){
        image2.center = location;
     }
    

    【讨论】:

    • Awww...我的错我想测试相等性。已更正,现在工作正常.. :) 感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    相关资源
    最近更新 更多