Hello.
I'm having problems setting the alpha value of a UIView subclass object. Any suggestions?
I have UIView project whose alpha property I'm manipulating to control brightness. I'm using a UISlider control to set the value of the alpha property in a UIView subclass as follows:
-(id)initWithFrame:(CGRect)rect andParent:(id)theParent {
self = [super initWithFrame: rect];
if (self !=nil) {
[self setParent:theParent];
theSlider = [[UISlider alloc] initWithFrame: CGRectMake(35.0,400.0,250,0)];
theSlider.minimumValue = 0.2;
theSlider.maximumValue = 1.0;
theSlider.value = 1.0;
theSlider.continuous = YES;
UIImage *maximumValueImage = [UIImage imageNamed:@"BrightSun.png"];
UIImage *minimumValueImage = [UIImage imageNamed:@"DimSun.png"];
theSlider.maximumValueImage = maximumValueImage;
theSlider.minimumValueImage = minimumValueImage;
theSlider.hidden = NO;
[theSlider addTarget:parent action: @selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[self addSubview:theSlider];
}
return self;
}
The sliderValueChanged method in the parent object changes the alpha value of another UIView subclass object, OverlayView. The parent object is a subclass of UIViewController, myViewController. The slider lives in a second UIView subclass named SliderView.
This seems to work. The problem comes up when I attempt to toggle the .hidden property of the UISlider. When I change the .hidden property to YES,
theSlider.hidden = YES;
The slider disappears, but the alpha value of the OverlayView object resets to 0.0. The value of the slider does not change. I want the alpha property of the OverlayView as set by
sliderValueChanged method to remain unchanged when the hidden property of the UISlider object changes.
Any suggestions as to what I'm doing wrong? Thanks.