imageView.clipsToBounds = YES;
have a try
想修改图片于View的相对坐标,可以增加一个CALayer用于存放图片,或者索性将一个UIImageView *a作为另一个UIView *b的subview,然后调整a的frame。
下面代码示范了如何使用CAlayer做到修改图片坐标
此类继承自UIView,setImageFrame方法可以修改图片相对于View的坐标或大小等。
//
// OTImageView.m
// ClipDemo
//
// Created by openthread on 5/31/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "OTImageView.h"
#import <QuartzCore/QuartzCore.h>
@implementation OTImageView
{
CALayer *_imageLayer;
}
#pragma mark - Image Methods
- (UIImage *)image
{
CGImageRef imageRef = (__bridge CGImageRef)_imageLayer.contents;
UIImage *image = [UIImage imageWithCGImage:imageRef];
return image;
}
- (void)setImage:(UIImage *)image
{
CGImageRef imageRef = image.CGImage;
_imageLayer.contents = (__bridge id)imageRef;
}
#pragma mark - Frame Methods
- (void)setImageFrame:(CGRect)imageFrame
{
_imageLayer.frame = imageFrame;
}
#pragma mark Life Cycle
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_imageLayer = [CALayer layer];
_imageLayer.backgroundColor = [UIColor blueColor].CGColor;
_imageLayer.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
[self.layer addSublayer:_imageLayer];
}
return self;
}
@end