简体   繁体   中英

UIBarButtonItem - Invalid tap glow size

I have a strange problem with glow that appears when pressing on a UIBarButtonItem in the UIToolbar control. When I set ImageInsets property to 4,0,0,0 the glow gets smaller every time I tap on it. Here is an illustration:

点击发光问题

The problem doesn't appear if I don't set imageInsets. The problem appears for all buttons in the UIToolbar. I don't have tap handlers. Making bigger inset (eg 8,0,0,0) produces the same result faster.

I appreciate any suggestions on how to solve the problem.

EDIT: Changed the code to Objective-C since the problem reproduces without MonoTouch as well.

It's default single view project. I added a toolbar and a UIBarButtonItem into it using storyboard designer. Created an outlet for the button.

#import "ViewController.h"

@implementation ViewController
@synthesize testBtn;

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIEdgeInsets insets = UIEdgeInsetsMake(8, 0, 0, 0);
    [testBtn setImageInsets:insets];
}

- (void)viewDidUnload
{
    [self setTestBtn:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

It is hard to see what the problem is without code. Would you mind posting the relevant parts of your code up? I am thinking it has something to do with you repeatedly incrementing the top inset by 4... I will edit my answer once I see the relevant code.

EDIT: So I am not familiar with Monotouch... and from the code you pasted I am assuming the constructor does indeed get called once. I am thinking there may be a bug in the Monotouch framework which is causing the imageinsets to be shifted by the specified amount (down 4) every time the button is tapped. I would check in the following order:

  1. That the delegate method tied to the button is not pointing to the constructor.
  2. Change the inset to (8,0,0,0) and in 5 taps do you see the same image as above (10x). If so it may be an issue with the monotouch framework or with how you hooked up your delegate method.

Sorry but I am unfamiliar with monotouch so I can't provide much more assistance. Unless you are locked into using Monotouch, I would strongly recommend you learn native Objective-C and program natively to avoid small pitfalls and headaches such as this. Objective-C and the iOS SDK is pretty elegant.

最后,我要求设计人员调整图像大小,从而摆脱imageSize属性的使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM