Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIImageView大小更改_Ios_Objective C_Uiimageview_Uinavigationbar_Uitapgesturerecognizer - Fatal编程技术网

Ios UIImageView大小更改

Ios UIImageView大小更改,ios,objective-c,uiimageview,uinavigationbar,uitapgesturerecognizer,Ios,Objective C,Uiimageview,Uinavigationbar,Uitapgesturerecognizer,我有一个带有自定义视图的导航栏。UIImageView和UILabel是标题视图的子视图。我将UIAPTgestureRecognitizer添加到titleView中,以便在用户点击它时显示另一个UIViewController。当您点击标题查看时,其他UIViewController将打开。但当你点击我的标题中的后退按钮时,UIImageView的大小会改变。这是密码 UIView *titleView = [[UIView alloc] initWithFrame: CGRectMake(

我有一个带有自定义视图的导航栏。UIImageView和UILabel是标题视图的子视图。我将UIAPTgestureRecognitizer添加到titleView中,以便在用户点击它时显示另一个UIViewController。当您点击标题查看时,其他UIViewController将打开。但当你点击我的标题中的后退按钮时,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;
以下是您可以看到更改的图像


我检查您的代码,将剪辑添加到边界,不需要两次标题框

_imageView.frame = CGRectMake(0, 0, 30, 30);
_imageView.layer.cornerRadius = 15.0;
_imageView.layer.masksToBounds = YES;
_imageView.clipsToBounds = true;

与其直接设置视图的框架,不如尝试使用;我怀疑发生的情况是,您的自定义视图在按下“上一步”按钮后被重新显示,并恢复为图像视图的
instrinsize

相反,您可以在子视图上禁用
translatesAutoResizengMaskintoConstraints
,然后添加约束以定位它们,最后向图像视图添加宽度和高度约束

如果你打算国际化你的应用程序,也建议使用自动布局——如果你正确设置了限制条件,那么翻译后的标题就会合适,你就不必再使用硬编码的值了