【发布时间】:2017-03-01 15:26:08
【问题描述】:
我有带有自定义视图的导航栏。 UIImageView 和 UILabel 是 titleView 的子视图。我将 UITapGestureRecognizer 添加到 titleView 以使其在用户点击它时显示另一个 UIViewController。当您点击 titleView 时,其他 UIViewController 会打开。但是当你在我的titleView 中单击返回按钮时,UIImageView 的大小会发生变化。这是代码
UIView *titleView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, 30)];
UILabel *title = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width/2, 30)];
title.text = _groupName;
[title setTextColor:[self colorFromHexString:@"#474747"]];
[title setFont:[UIFont fontWithName:@"Roboto-Bold" size:16]];
[title setTextAlignment:NSTextAlignmentCenter];
[title setBackgroundColor:[UIColor clearColor]];
_imageView.frame = CGRectMake(0, 0, 30, 30);
_imageView.layer.cornerRadius = 15.0;
_imageView.layer.masksToBounds = YES;
_imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
_imageView.layer.borderWidth = 0.1;
_imageView.contentMode = UIViewContentModeScaleAspectFit;
title.frame = CGRectMake(title.frame.origin.x+20, title.frame.origin.y, self.view.frame.size.width/2, 30);
UITapGestureRecognizer *recognizer;
recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(titleTapped:)];
titleView.userInteractionEnabled = YES;
[titleView addGestureRecognizer:recognizer];
[titleView addSubview:title];
[titleView setBackgroundColor:[UIColor clearColor]];
[titleView addSubview:_imageView];
self.navigationItem.titleView = titleView;
【问题讨论】:
标签: ios objective-c uiimageview uinavigationbar uitapgesturerecognizer