IOS Gradient在ScrollView的最后一个视图中无法正常工作

时间:2014-08-27 08:44:44

标签: ios objective-c uiscrollview

我已经创建了一个滚动视图programatticaly并添加了一些视图,每个新视图都在另一个下面,都具有渐变背景。但是,屏幕上可以看到的最后一个视图永远不会应用渐变。是什么导致了这个问题?这是我的代码:

float width = [[UIScreen mainScreen] bounds].size.width;
        for(id object in myDictionary)
        {
            vert_indent += 50; //a float initialised elsewhere
            UIView *invView = [[UIView alloc]init];
            invView.frame=CGRectMake(0, vert_indent, width, 50);
            invView.backgroundColor = [UIColor clearColor];
            CAGradientLayer *gradient = [CAGradientLayer layer];
            gradient.frame = invView.bounds;
            float colourGrey = 240.0f/255.0f; //a very light grey
            gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor], (id)[[UIColor colorWithRed:colourGrey green:colourGrey blue:colourGrey alpha:1.0]CGColor], nil];
            [invView.layer insertSublayer:gradient atIndex:0];
            [scroll addSubview:invView]; //scroll is the scroll view
        }

编辑:当我使渐变变暗时,我注意到最后一个可见视图在视图的一部分不可见时仅丢失了它的渐变。

0 个答案:

没有答案