要求:
我想用封面照片进行用户注册。所以我想像 Facebook 一样覆盖照片。
我的问题:
2) 当我在封面照片上设置图像时,它会自行拉伸(stretch),不应该拉伸(stretch)..
3) 用户应该能够使用滚动或手势进行调整。
请帮帮我..
最佳答案
最好的实现方式是:
第 1 步:将您的 Imageview 放入与 ImageView 想要的相同框架的一个 View 中。
第 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;
}
}
}
你已经完成了.. 希望这有帮助..:)
关于ios - 在 UIImageView 上调整图像,如 FB 封面照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37605414/