ios - 在 UIImageView 上调整图像,如 FB 封面照片

标签 ios objective-c uiimageview uigesturerecognizer

enter image description here

要求:

我想用封面照片进行用户注册。所以我想像 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/

相关文章:

ios - Objective-C SpriteKit – 如何制作圆形按钮

ios - 来自 xib 的 View 存在奇怪的约束/UI 错误

ios - GCD 和 iOs 中的多个委托(delegate)

iOS//显示html -> 富文本

ios - 在 iOS 中将图像大小减小至最大 100 kb,并固定尺寸 512x512

android - 如何在 Google Play Console 和 App Store Connect 中为单个应用配置多个自动续订订阅

iphone - 在单键 NSMutableDictionary 下添加两个对象

ios - UIWebView 在用户点击链接标签时禁用高亮

ios - 如何以编程方式创建一个 UIView,其中包含一个 'cutoff' UIImageView?

ios - 在 Objective-C 中屏蔽 View