单击Button后,UIView alpha正在消失

时间:2014-10-30 12:50:24

标签: ios objective-c cocoa-touch uiview uikit

我有一个容器UIView和一个UIView,其中包含alpha 0.7f,还有一个自定义UIButton,图片已添加到该容器UIView。现在每当我点击按钮时,透明UIView上的一个大方块就会消失并保持这种状态。我不知道为什么会这样。任何人都可以帮我解决这个问题吗?

UIWindow* window = [[UIApplication sharedApplication] keyWindow];

UIView *viewTestOverViewContainer = [[UIView alloc] initWithFrame:window.bounds];

UIView *viewOverlay = [[UIView alloc] initWithFrame:viewTestOverViewContainer.frame];
viewOverlay.backgroundColor = [UIColor blackColor];
viewOverlay.alpha = 0.7;
[viewTestOverViewContainer addSubview:viewOverlay];

float x = (window.bounds.size.width/2)-98;
float y = (window.bounds.size.height/2)-98;
UIView *viewTestPicContainer = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, 204, 204)];
viewTestPicContainer.backgroundColor = [UIColor whiteColor];
viewTestPicContainer.layer.cornerRadius = viewTestPicContainer.frame.size.width / 2;
viewTestPicContainer.clipsToBounds = YES;
viewTestPicContainer.backgroundColor = [UIColor whiteColor];
[viewTestPicContainer setContentMode:UIViewContentModeScaleAspectFill];

UIImageView *imgViewTestPic = [[UIImageView alloc] initWithFrame:CGRectMake(2, 2, 200, 200)];
imgViewTestPic.image = [UIImage imageNamed:@"portrait_eyes_14.jpg"];

imgViewTestPic.layer.cornerRadius = imgViewTestPic.frame.size.width / 2;
imgViewTestPic.clipsToBounds = YES;
imgViewTestPic.backgroundColor = [UIColor whiteColor];
[imgViewTestPic setContentMode:UIViewContentModeScaleAspectFill];
[viewTestPicContainer addSubview:imgViewTestPic];
[viewTestOverViewContainer addSubview:viewTestPicContainer];

UIButton *btnLeftArrow = [UIButton buttonWithType:UIButtonTypeCustom];
btnLeftArrow.frame = CGRectMake(46, 275, 12, 20);
[btnLeftArrow setImage:[UIImage imageNamed:@"popup-left-arrow"] forState:UIControlStateNormal];
[viewTestOverViewContainer addSubview:btnLeftArrow];

UIButton *btnRightArrow = [UIButton buttonWithType:UIButtonTypeCustom];
btnRightArrow.frame = CGRectMake(270, 275, 12, 20);
[btnRightArrow setImage:[UIImage imageNamed:@"popup-right-arrow"] forState:UIControlStateNormal];
[viewTestOverViewContainer addSubview:btnRightArrow];

[window addSubview:viewTestOverViewContainer];

之前: before

点击左箭头按钮后 after

0 个答案:

没有答案