使用cornerradius IOS进行圆形问题时发出相关的UIimageView问题

时间:2013-07-10 05:41:02

标签: iphone ios cornerradius

我在UIBiew中使用了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];
}

3 个答案:

答案 0 :(得分:4)

试试这段代码:

_roundView.layer.cornerRadius = _roundView.frame.size.height / 2;
_roundView.layer.masksToBounds = YES;

绑定面具是强制性的.. 此外,如果您使用公式而不是直接值,您的代码将变得更加灵活。 我希望它可以帮到你!!祝你好运!!

答案 1 :(得分:2)

尝试使用这个..

_roundView.layer.masksToBounds = YES; 

答案 2 :(得分:2)

尝试以下代码

roundView.layer.cornerRadius = 46;
_roundView.layer.masksToBounds = YES;


flag=0;



selectImage.layer.cornerRadius = 46;
selectImage.layer.masksToBounds = YES;



imageFrame = selectImage.frame;