How to add a UIImage below UIBarButton item

2019-09-02 06:19发布

I have a UIView that appears on screen when a user taps a UIBarButtonItem in my UINavigationController. The button already has an image, which works fine.

What I would like to do is when the UIBarButtonItem is tapped a small image appears right below it - still partly in the UINavigationController - so it looks like a speak bubble has appeared. It seems this would be quite difficult.

Is this possible? Or should I look at just moving the UIView down a few points and adding the UIImage between the UIView and the UINavigationController?

I don't want to change the size / high of the UIBarButtonItem or its current image.

1条回答
疯言疯语
2楼-- · 2019-09-02 07:06

On UIBarButtonItem's tap event : Add on window

AppDelegate *yourAppDelObj = (AppDelegate*)[UIApplication sharedApplication].delegate
UIImageView *yourImgView = [UIImageView alloc] initWithImage:[UIImage imagenamed:@"image name here"];
//set frame below UIBarButtonItem
//add tag
[yourImgView setTag:9999];
[yourAppDelObj.window addSubView:yourImgView];

Remove addedSubView from window when not needed:

//Remove the UIView
UIView *addedImgView = [yourAppDelObj.window viewWithTag:9999];
[addedImgView removeFromSuperView];
查看更多
登录 后发表回答