このコードは正しいですか?
UIImageView* framebadgeOrAccessoryImage = [[UIImageView alloc]initWithFrame:sizeOfFrameOrAccessoriesView];
[framebadgeOrAccessoryImage setCenter:imageArea.center];
[framebadgeOrAccessoryImage setContentMode:UIViewContentModeScaleAspectFit];
[framebadgeOrAccessoryImage setImage:badgeOrAccessoryImage];
[framebadgeOrAccessoryImage setTag:iObjectTag];
[framebadgeOrAccessoryImage setObservationInfo:@"BadgeAccessories"];
[framebadgeOrAccessoryImage setExclusiveTouch:YES];
iObjectTag++;
[framebadgeOrAccessoryImage setMultipleTouchEnabled:YES];
[framebadgeOrAccessoryImage setBackgroundColor:[UIColor clearColor]];
[framebadgeOrAccessoryImage setUserInteractionEnabled:YES];
[imageArea addSubview:framebadgeOrAccessoryImage];
selectedItem = framebadgeOrAccessoryImage;
[framebadgeOrAccessoryImage release];
設定したタグを使用して、他のメソッドで「framebadgeOrAccessoryImage」を使用しています。コードの最後の行で行ったように「framebadgeOrAccessoryImage」をリリースするか、リリース後に nil に割り当てる必要がありますか?
ここでは「framebadgeOrAccessoryImage」が「selectedItem」という名前で使用されています。
- (void)panRecognized:(UIPanGestureRecognizer *)gestureRecognizer
{
if(selectedItem.image && [gestureRecognizer isEnabled])
{
UIImageView *piece = selectedItem;
if ((([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged)) && [((NSString*) [piece observationInfo]) isEqualToString:@"BadgeAccessories"])
{
CGPoint translation = [gestureRecognizer translationInView:[piece superview]];
[piece setCenter:CGPointMake([piece center].x + translation.x, [piece center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded ||[gestureRecognizer state] == UIGestureRecognizerStateCancelled || [gestureRecognizer state] == UIGestureRecognizerStateFailed)
{
if(CGRectContainsPoint([[self view]viewWithTag:RECYCLEBIN_TAG].frame, [gestureRecognizer locationInView:imageArea]))
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc]init];
[objectsAdded removeObjectForKey:[NSString stringWithFormat:@"%d",selectedItem.tag]];
[pool release];
[UIView beginAnimations:NULL context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDidStopSelector:@selector(propDeleted:finished:context:)];
[UIView setAnimationDelegate:self];
[selectedItem setFrame:CGRectMake(selectedItem.frame.origin.x, selectedItem.frame.origin.y, 5, 5)];
selectedItem.center = [[[self view]viewWithTag:RECYCLEBIN_TAG]center];
[UIView commitAnimations];
}
else
{
[self applyEffectOnTouch:0];
}
}
}
}