我在 XIB 文件中使用了 UIView。在这个视图中有一个 UIImageView 和一个相同大小的按钮。我想让那个视图变成圆形,为此我正在使用cornerRadius。视图的大小为 92 * 92,这就是我采用 46 的cornerRadius 使其变圆的原因。下面是我的代码,我正在评论我在代码本身中遇到的问题。
- (void)viewDidLoad
{
[super viewDidLoad];
_roundView.layer.cornerRadius = 46;
flag=0;
selectImage.layer.cornerRadius = 46;
NSLog(@"%f",_roundView.frame.size.height);
NSLog(@"%f",_roundView.frame.size.width);
imageFrame = selectImage.frame;
// when first view appear its perfectly round
// this is how i pick image from gallery
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info {
self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
UIImage *shrunkenImage = shrinkImage(chosenImage, imageFrame.size);
self.imagee = shrunkenImage;
NSLog(@"%f",_roundView.frame.size.height); nslog = 92
NSLog(@"%f",_roundView.frame.size.width); nslog = 92
NSLog(@"%f",_roundView.layer.cornerRadius); nslog = 46
NSLog(@"%f",selectImage.frame.size.height); nslog = 92
NSLog(@"%f",selectImage.frame.size.width); nslog = 92
NSLog(@"%f",selectImage.layer.cornerRadius); nslog = 46
selectImage.image = imagee;
selectImage.layer.cornerRadius = 46;
// now the issue is Image gets selected but it become rectangular 92 * 92
}
[picker dismissModalViewControllerAnimated:YES];
}