ios - 从 super View 转换点时委托(delegate)不工作

标签 ios objective-c

我被一个问题困扰了几天,我想是时候寻求帮助了。

我有一个 UIView 类“BonusObjects”,它被设置为 ViewController 的委托(delegate)。

我在此类中添加了一些 UIImageView,开始使用 NSTimer 将它们移向屏幕边缘,并尝试查看它们是否与 ViewController.m 中的 UIImageView 相交。我将目标对象的坐标作为 int 并检查来自 BonusObjects 的图像的 X 和 Y 是否在目标附近的任何地方。

由于来自 BonusObject 的图像 X=0,我必须从 super View 转换它们的坐标。像那样:

CGPoint newPoint = [[self superview]convertPoint:internal.center 
                                        fromView:[internal superview]];

bonusX= newPoint.x;

这是真正的问题:为什么委托(delegate)在这个 if 中不起作用声明:

if (padX < bonusX && bonusX < padX+40 && padY <= internal.frame.origin.y) {

    [[self delegate] bonusEffect:internal.tag];

    [internal removeFromSuperview];
    internal=NULL;
}

但如果我将它从 if 中取出,或者将 bonusX 更改为某个不是从父 View 中获取的随机值,它就会起作用。

如果一切正常 - 它会删除图像,并显示正确的 .tag 值。

如果需要,我可以提供更多代码。

编辑:代表是(null)在那if , 但在它外面是 <ViewController: 0xc03e600> .

EDIT2:这是我设置委托(delegate)的方式:

在 BonusObjects.h 中

@protocol BonusDelegate

-(void)bonusEffect:(int)effect;

@end


@interface BonusObjects : UIView <UIApplicationDelegate> {

    id <BonusDelegate> delegate;
     } @property (nonatomic)  id <BonusDelegate> delegate;

在 ViewController.h 中:

#import "BonusObjects.h"

@interface ViewController : UIViewController <BonusDelegate, ADBannerViewDelegate> {


     BonusObject *bonusView;
       }

在 ViewController.m 中:

 bonusView = [[BonusObjects alloc] init];
 [bonusView setDelegate:self];

最佳答案

(padX < bonusX && bonusX < padX)总是会失败

关于ios - 从 super View 转换点时委托(delegate)不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14319978/

相关文章:

ios - 各种屏幕尺寸的布局问题

objective-c - 我的 App Store 应用显示 "Test Ad"iAd

ios - 如何阻止 iAds 在 xcode 中扭曲 SKScene?

ios - 将 CLLocationCoordinate2D 返回到结构

ios - Objective-C ,[NSString initWithFormat] 究竟是做什么的?

ios - Crashlytics - 检测到带有 API key xxx 的目标构建,但我们期待 yyy(组织...)

ios - 子类化 UIViewController,何时以及何时不

iphone - 如何清除uitableview的所有行

objective-c - 我需要在释放之前从 UIButton 中删除目标吗?

iphone - Storyboard标识符的代码完成