0

Я реализовал этот обычай класса для Панель навигации моего проекта: Video with IssueIOS Пользовательские UINavigationBar - barButtonItems получать касание из пределов

#import "PTTNavigationBar.h" 
@implementation PTTNavigationBar 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 

} 
    return self; 
} 


// Overriding drawRect: perform custom drawing. 
// An empty implementation adversely affects performance during animation. 

- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    UIImage *navBarImage = UIIMAGE_NAMED(kNavBarBackGroundImage); 
    [navBarImage drawInRect:CGRectMake(0, 0, NAVBAR_SIZE.width , NAVBAR_SIZE.height)]; 

    [self setBackgroundColor:[UIColor clearColor]]; 

} 

- (CGSize)sizeThatFits:(CGSize)size { 

    //[self setTitleVerticalPositionAdjustment:-12 forBarMetrics:UIBarMetricsDefault]; 
    CGRect frame = [UIScreen mainScreen].applicationFrame; 
    CGSize newSize = CGSizeMake(frame.size.width , NAVBAR_SIZE.height); 
    [self layoutSubviews]; 

    return newSize; 
} 


-(void) layoutSubviews 
{ 
    [super layoutSubviews]; 

    [self setBackgroundColor:[UIColor clearColor]]; 

    for (UIView *view in self.subviews) 
    { 
     CGRect frame = view.frame; 
     frame.origin.y = 6; 
     view.frame = frame; 
    } 


} 

@end 

кто может помочь мне с этим ?? thx

+0

Как вы добавляете barButtonItems? это пользовательские кнопки? –

+0

его кнопку назад. по умолчанию – luca

+0

Это функция по умолчанию в iOS, вы можете проверить настройки приложения. Если вы действительно хотите ограничить прикосновение, тогда мой ответ будет работать. –

ответ

1

Я предполагаю, что вы добавляете пользовательские кнопки влевоBarButton через код.

Следующий код должен ограничить контакт внутри границ barButtonItem

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button setImage:buttonImage forState:UIControlStateNormal]; 
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height); 
[button addTarget:self action: @selector(handleBackButton)forControlEvents:UIControlEventTouchUpInside]; 

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height)]; 
[view addSubview:button]; 

UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:view]; 
self.navigationItem.leftBarButtonItem = customBarItem; 

 Смежные вопросы

  • Нет связанных вопросов^_^