相关疑难解决方法(0)

传递UIImage.CGImage时,CGContextDrawImage将图像上下颠倒

有谁知道为什么CGContextDrawImage会把我的形象颠倒过来?我从我的应用程序加载图像:

UIImage *image = [UIImage imageNamed:@"testImage.png"];
Run Code Online (Sandbox Code Playgroud)

然后简单地要求核心图形将其绘制到我的上下文中:

CGContextDrawImage(context, CGRectMake(0, 0, 145, 15), image.CGImage);
Run Code Online (Sandbox Code Playgroud)

它呈现在正确的位置和尺寸,但图像是颠倒的.我一定错过了一些非常明显的东西吗?

cocoa-touch core-graphics ios cgcontextdrawimage

178
推荐指数
7
解决办法
11万
查看次数

Interface Builder中的"Mode"属性是什么,提供"Scale to fill","Aspect fit"等?

我想知道下载"模式"是什么?它包含"缩放以填充","纵横适合"等.到目前为止,我从来没有改变它,但我仍然很好奇它可以用于什么.有人可以解释一下吗?

cocoa-touch interface-builder

39
推荐指数
3
解决办法
3万
查看次数

在UIImageView上添加渐变

我试图在我的上添加一个子图层,UIImageView但它不起作用.

  • 我有一组10个图像命名为photo0to photo9,我用5s的计时器显示它.
  • 出口shanghaiImage是我的背景

我想在这个marty上添加一个渐变,如:透明(顶部)到黑色(底部).

谢谢您的帮助 :)

这是我在Swift 3中的代码.

这部分很好:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var shanghaiImage: UIImageView!

// beginning index
var _curentImageIndex:Int = 0
// number of images
let NUMBER_OF_IMAGES:Int = 10
// creation of the Timer
var _uiTimer:Timer?


override func viewDidLoad() {
    super.viewDidLoad()
    showPhoto(atIndex: _curentImageIndex)
}

// MARK TIMER ---------

func selectNewTimer(){
    if let existingTimer:Timer = _uiTimer{
        existingTimer.invalidate()
    }
    _uiTimer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(ViewController.showNextImage), userInfo: …
Run Code Online (Sandbox Code Playgroud)

uiimageview uicolor ios cagradientlayer swift3

8
推荐指数
2
解决办法
1万
查看次数

Swift:将图像添加到 CAShapeLayer

我有一个带有填充颜色的 CAShapeLayer,并且想在这个形状的中心添加一个图标:

var shape = CAShapeLayer()
shape.fillColor = UIColor(white: 0.90, alpha: 1).CGColor
var image = UIImage(named: "some_image")
shape.contents = image?.CGImage
Run Code Online (Sandbox Code Playgroud)

这段代码可以编译并显示灰色形状 - 但没有图像。:(

我查看了这些帖子,但我无法像他们那样投射 CGImage。

在 CALayer 中添加 UIImage使用普通 CALayer 显示图像或 UIImage

还有其他方法吗?或者 id 转换的解决方法?

完整代码:

视图控制器.swift

import UIKit

class ViewController: UIViewController {

    @IBOutlet var menuView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(animated: Bool) {

        let menu: CircularMenu = CircularMenu(frame: menuView.bounds, numberOfMenuItems: …
Run Code Online (Sandbox Code Playgroud)

uiimage cgimage cashapelayer swift ios8

1
推荐指数
1
解决办法
5287
查看次数

在UIImageView上绘制而不替换其原始图像iOS

此代码对imageview进行了更改,但它替换了原始图像.我需要在原始图像上进行编辑而不是替换它.

- (void)drawShapes {
    //NSLog(@"In drawShapes!");

    UIGraphicsBeginImageContext(self.planView.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    for(myShape *i in _collection) {
        [self drawShapesSubroutine:i contextRef:context];
        if(i.selected == true) {
            CGContextSetLineWidth(context, 1.0f);
            CGContextSetStrokeColorWithColor(context, [[UIColor darkGrayColor] CGColor]);
            float num[] = {6.0, 6.0};
            CGContextSetLineDash(context, 0.0, num, 2);

            CGRect rectangle;
            [self drawShapeSelector:i selectorRect: &rectangle];
            CGContextAddRect(context, rectangle);
            CGContextStrokePath(context);


            //tapped = true;
        }
    }

    if(!skipDrawingCurrentShape && (selectedIndex == -1)) {
        [self drawShapesSubroutine:_currentShape contextRef:context];
    }
    self.planView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}
Run Code Online (Sandbox Code Playgroud)

当我删除此行时:

self.planView.image = UIGraphicsGetImageFromCurrentImageContext();
Run Code Online (Sandbox Code Playgroud)

图像不会消失但也不会消失.我需要绘制而不删除原始照片.

core-graphics objective-c uiimageview ios

0
推荐指数
1
解决办法
419
查看次数