触摸屏幕时ios应用程序崩溃
<p><p>在我的应用程序中,每 2 秒通过 NSTimer 调用一个方法 (addCoinTarget)。我想让应用程序在调用 UIView(在本例中为 Coin)时执行 NSLog。但是,无论何时触摸屏幕,即使它不在 Coin 对象上,应用程序都会崩溃并出现以下错误:</p>
<blockquote>
<p>error: memory read failed for 0x42200000</p>
</blockquote>
<p>这是创建 Coin 对象的方法:</p>
<pre><code>-(void)addCoinTarget {
Coin *coinTarget = [initWithFrame:CGRectMake(-20, -20, 27, 40)];
;
// Determine where to spawn the coin along the Y axis
int minYc = coinTarget.frame.size.width/2;
int maxYc = screen.size.width - coinTarget.frame.size.width/2;
int rangeYc = maxYc - minYc;
int actualYc = (arc4random() % rangeYc) + minYc;
// Determine speed of the target
int minDurationc = 2.0;
int maxDurationc = 4.0;
int rangeDurationc = maxDurationc - minDurationc;
int actualDurationc = (arc4random() % rangeDurationc) + minDurationc;
theAnimation=;
theAnimation.duration = 3.0;
theAnimation.repeatCount=1.0;
theAnimation.autoreverses=NO;
];
];
theAnimation.delegate = self;
[CATransaction setCompletionBlock:^{
;
}];
;
</code></pre>
<p>另外,这是我到目前为止的触摸代码:</p>
<pre><code>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = ;
CGPoint location = ];
NSLog(@"touched");
}
</code></pre>
<p>我做错了什么?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>被触摸的 View 的引用计数为零,因此它已被释放。</p></p>
<p style="font-size: 20px;">关于触摸屏幕时ios应用程序崩溃,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22391893/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22391893/
</a>
</p>
页:
[1]