0

我正在向我的视图控制器添加一个名为bookViewContainer的UIView,并且我想要检测其规模何时使用KVO进行更改。这里是我的viewDidLoad在UIView上创建KVO时出错

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    bookViewContainer = [[UIView alloc] initWithFrame:self.view.bounds]; 
    [self.view addSubview:bookViewContainer]; 

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)]; 
    [bookViewContainer addGestureRecognizer:tap]; 

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchRecognized:)]; 
    [bookViewContainer addGestureRecognizer:pinch]; 

    [bookViewContainer addObserver:self forKeyPath:@"transform.scale" options:NSKeyValueObservingOptionNew context:NULL]; 
} 

和我observeValueForKeyPath

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 
{ 
    NSLog(@"%@", object); 
} 

然而,当我运行该项目,我立刻得到错误:

An instance 0x1d844ca0 of class NSConcreteValue was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: ( Context: 0x0, Property: 0x1d844db0> )

我用志愿前(但从来没有在transform.scale),并且该视图绝对不会被释放(我正在使用ARC)。我试过用scale代替,但没有任何反应。我究竟做错了什么?

回答

0

解决方案:我需要自己使用transform,而不是它的属性。任务完成!