如何在iOS中实现水平缩放视图?

时间:2016-03-17 07:00:43

标签: ios objective-c uiscrollview horizontalscrollview

我已根据代码中的设计要求使用TSRDialScrollView库。

但无法解决一些问题。

从以下链接引用:

https://www.cocoacontrols.com/controls/trsdialscrollview

我在代码中做了一些更改

- >清除背景颜色

CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor clearColor] set];
CGContextFillRect(context, rect);

但它显示黑色。

- >在视图反转后设置标签

- (void)drawLabelWithContext:(CGContextRef)context
                     atPoint:(CGPoint)point
                        text:(NSString *)text
                   fillColor:(UIColor *)fillColor
                 strokeColor:(UIColor *)strokeColor {


    // We want the label to be centered on the specified x value
    NSInteger label_y = ((point.y-100) - (boundingBox.width / 2));
}

- >通过在代码中将次要和主要刻度长度更改为负值来反转整个视图。

- (void)drawTicksWithContext:(CGContextRef)context atX:(long)x
{
    CGPoint point = CGPointMake(x, self.frame.size.height);
    CGContextSetShadowWithColor(
                                context,
                                self.shadowOffset,
                                self.shadowBlur,
                                self.shadowColor.CGColor);

    if ([self isMajorTick:x]) {
        [self drawMajorTickWithContext:context
                               atPoint:point
                             withColor:self.majorTickColor
                                 width:self.majorTickWidth
                                length:-self.majorTickLength];
        // Draw the text
        //
        // 1) Take the existing position and subtract off the lead spacing
        // 2) Divide by the minor ticks to get the major number
        // 3) Add the minimum to get the current value
        //
        int value = (point.x - self.leading) / self.minorTickDistance + _minimum;

        NSString *text = [NSString stringWithFormat:@"%i", value];
        [self drawLabelWithContext:context
                           atPoint:point
                              text:text
                         fillColor:self.labelFillColor
                       strokeColor:self.labelStrokeColor];

    } else {

        CGContextSaveGState(context);
        [self drawMinorTickWithContext:context
                               atPoint:point
                             withColor:self.minorTickColor
                                 width:self.minorTickWidth
                                length:-self.minorTickLength];
        // Restore the context
        CGContextRestoreGState(context);
    }
} 

我想要进行缩放,如下所示。

Scaling image

1)通过调整偏移量,scrollview的视图应该在中间。(i,当它滚动到最小值时,0的位置不在视图的中间)。

2)我希望背景颜色是清晰的颜色。

3)根据设计,如何将红色设置为要修复的中间线?

4)如何在中间显示浅灰色,如图所示?

感谢您的帮助,请建议如何实现这一点,我真的需要完成这项非常需要的任务。

提前致谢。

1 个答案:

答案 0 :(得分:0)

  

TRSDialView.m

文件: -

[['avatar'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg ,jpeg', 'wrongExtension'=>'{extensions} files only', 'on'=>'update'] 添加- (instancetype)initWithFrame:(CGRect)frame

self.opaque = NO;内部方法中添加以下- (void)drawRect:(CGRect)rect行代码

下面的代码
CGContextRef context = UIGraphicsGetCurrentContext();

上面的代码将清除背景颜色。

// Fill the background CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor); // CGContextFillRect(context, rect); CGContextClearRect(context, rect);

中调整offsetwidth constraint添加到TRSDialView

可以在Storyboard

中将红线和灰色视图添加为subview