这段代码正确吗?
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];
}
}
}
}