UIImageView automatically removes itself from self.view

tutorialImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Tap to Start.png"]]; tutorialImage.frame = CGRectMake(0, 0, 1024, 768); [tutorialImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(blankMethod)]]; tutorialImage.userInteractionEnabled = YES; // i use this line and the previous line so that the user can't press any buttons behind the image tutorialImage.alpha = 0; [self.view addSubview:tutorialImage]; [self.view bringSubviewToFront:tutorialImage]; [UIView animateWithDuration:1.0f animations:^{ tutorialImage.alpha = 1; } completion:^(BOOL finished) { [self.view addSubview:tutorialImage]; // this line makes the image come back }]; 

I know that you probably won’t be able to infer the problem only from this code, but is there anything in this code that makes tutorialImage automatically remove the add-in from it?

Anyway, during the UIView animation, the image gradually disappears as normal, and then disappears. If I add this last line of code (commented out), the UIView animation will cause the image to fade and flash once halfway. I just added this image, and there is no code telling him to remove myself from the supervisor.

Let me know if you have any ideas for fixing the problem or show you more code, I will check often.

In addition, I tried to restart the simulator, which did not work, and the tutorial image was declared in the file h UIImageView *tutorialImage; . The console does not show any errors or anything when a problem occurs or something else.

Edit:

Good, weird. I changed the declaration in the H file with UIImageView *tutorialImage; before @property (strong, nonatomic) UIImageView *tutorialImage; and then used the _tutorialImage fixed problem. Is this somehow related to a strong parameter? I will note who will someday be able to explain what is happening, how to do it right.

+4
source share
1 answer

When you have a weak link, ARC will disable the object if it is no longer there (when the object does not point to an object with a strong pointer). When you change @property to strong, you are now reporting to ARC that the object remains on until the parent (your view controller) is deleted.

0
source

Source: https://habr.com/ru/post/1493336/


All Articles