在 UIImageView 上调整图像,如 FB 封面照片
Image adjust on UIImageView like FB cover photo
要求:
我想用封面照片注册用户。所以我想像Facebook一样封面照片。
我的问题:
2) 当我在封面照片上设置图像时,它会自动拉伸它不应该拉伸..
3) 用户应该能够使用滚动或手势进行调整。
请帮帮我..
实现它的最佳方法是:
第 1 步:将您的 Imageview 放在与 ImageView 想要的同一帧的一个视图中。
第 2 步:设置图像内容模式和 userInteractionEnabled
YourImageView.contentMode=UIViewContentModeScaleAspectFill;
YourImageView.userInteractionEnabled=YES;
第 3 步:声明平移手势
@property (strong, nonatomic) UIPanGestureRecognizer *panGesture;
第 4 步:定义 PanGesture 并分配 YourImageview。
self.panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureComplete:)];
[YourImageView addGestureRecognizer:self.panGesture];
(已更新)
第 5 步:添加以下方法..
-(void)panGestureComplete : (UIPanGestureRecognizer *)parameter{
if (parameter.state != UIGestureRecognizerStateEnded && parameter.state != UIGestureRecognizerStateFailed) {
CGPoint point=[parameter locationInView:parameter.view.superview];
// _ViewContainer is the View in which image lies..
if ( CGRectContainsPoint(_ViewContainer.bounds, point) ) {
// Point lies inside the your view Container bounds.
CGPoint pntTemp=_imgView.center;
pntTemp.y=point.y;
parameter.view.center=pntTemp;
}
}
}
大功告成..
希望这有帮助.. :)
要求:
我想用封面照片注册用户。所以我想像Facebook一样封面照片。
我的问题:
2) 当我在封面照片上设置图像时,它会自动拉伸它不应该拉伸..
3) 用户应该能够使用滚动或手势进行调整。
请帮帮我..
实现它的最佳方法是:
第 1 步:将您的 Imageview 放在与 ImageView 想要的同一帧的一个视图中。
第 2 步:设置图像内容模式和 userInteractionEnabled
YourImageView.contentMode=UIViewContentModeScaleAspectFill;
YourImageView.userInteractionEnabled=YES;
第 3 步:声明平移手势
@property (strong, nonatomic) UIPanGestureRecognizer *panGesture;
第 4 步:定义 PanGesture 并分配 YourImageview。
self.panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureComplete:)];
[YourImageView addGestureRecognizer:self.panGesture];
(已更新) 第 5 步:添加以下方法..
-(void)panGestureComplete : (UIPanGestureRecognizer *)parameter{
if (parameter.state != UIGestureRecognizerStateEnded && parameter.state != UIGestureRecognizerStateFailed) {
CGPoint point=[parameter locationInView:parameter.view.superview];
// _ViewContainer is the View in which image lies..
if ( CGRectContainsPoint(_ViewContainer.bounds, point) ) {
// Point lies inside the your view Container bounds.
CGPoint pntTemp=_imgView.center;
pntTemp.y=point.y;
parameter.view.center=pntTemp;
}
}
}
大功告成.. 希望这有帮助.. :)