UIView

设置亮度

通过修改alpha可以调节亮度,但会出现透明问题。还可以通过添加一个子view来调节亮度。

-(void)setAdView:(UIView*)adView opacity:(float)opacity
{
    if(opacity<1.0)
    {
        UIView* v=[adView viewWithTag:KMaskViewTag];
        if(!v)
        {
            v=[[[UIView alloc] initWithFrame:adView.bounds] autorelease];
            v.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:opacity];
            v.tag=KMaskViewTag;
            v.userInteractionEnabled=NO;
            [adView addSubview:v];
            
            v.alpha=0.0;
            [UIView animateWithDuration:0.30 animations:^{
                v.alpha=1.0;
            }];
        }
    }
    else
    {
        UIView* v=[adView viewWithTag:KMaskViewTag];

        [UIView animateWithDuration:0.30 animations:^{
            v.alpha=0.0;
        } completion:^(BOOL finished) {
            [v removeFromSuperview];
        }];
    }
}

viewWithTag

viewWithTag方法会在所有子view中递归查询,返回找到的第一个视图。

侧移效果实现过程

对框架view照相,把要显示的新view添加到框架view中,把照相view添加到框架view中,对照相view执行侧移动画,即动画中改变它的frame。相反的过程恢复到原状态。

    UIView* mainView = self.navigationController.view;
    UIImage* captureImage = [mainView captureView];

    [mainView addSubview:newView];
    UIImageView* theCaptureView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, mainView.frame.size.width, mainView.frame.size.height)];
    theCaptureView.backgroundColor = [UIColor whiteColor];
    [theCaptureView setImage:captureImage];
    [mainView addSubview:theCaptureView];
    [UIView animateWithDuration:0.25f animations:^{
        [theCaptureView setFrame:CGRectMake(-245, 44, mainView.frame.size.width, mainView.frame.size.height-44*2)]; //320-245=75
    } completion:^(BOOL finished) {
        theCaptureView.userInteractionEnabled = YES;
        UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recoveryView:)];
        [theCaptureView addGestureRecognizer:tap];
    }];
- (void)recoveryView:(id)sender
{
    UIView* mainView = [self.navigationController view]; n]
    if (theCaptureView) {
        [UIView animateWithDuration:0.25f animations:^{
            [theCaptureView setFrame:CGRectMake(0, 0, mainView.frame.size.width, mainView.frame.size.height)];
        } completion:^(BOOL finished) {
            [theCaptureView removeFromSuperview];
            [theNewView removeFromSuperview];
        }];
    }
}

- (UIImage*)captureView
{
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0.0);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage* screenImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImg;
}

contentMode

按钮中的图片等比适应按钮的尺寸

imageView.clipsToBounds=YES;
button.imageView.contentMode=UIViewContentModeScaleAspectFill;
button.imageView.contentMode=UIViewContentModeScaleAspectFit;

图片全圆角

imageView_.layer.cornerRadius = 15;//width/2
imageView_.layer.masksToBounds = YES;

如果需要全圆角边框可以在父view相同位置插入一个稍大一点的全圆角背景图,或尝试设置border。

 

UIImage

imageName会把image缓存到手机内存里,不适合大量图片浏览会越来越卡。

imageWithContentFile是只显示图片而不加载到手机内存里。所以在出来大量图片浏览的时候要用imagewithcontentfile。

尺寸

父view尺寸小,默认情况下内部的大按钮仍会显示全。

发表评论