小编Mar*_* A.的帖子

禁用Xcode Storyboard中的约束

我正在尝试布局一个非常简单的视图.我在视图中放置了4个自定义按钮,如间距.但是当我运行应用程序时,我得到两个不同大小的按钮.我在这里包含了故事板和模拟器图像.

我会喜欢禁用约束,但无法找到它的位置!我真的不想要他们.这只是一个简单的原型应用程序,最后我甚至没有这些按钮,我将把所有内容都放在代码中.

我试过拖动4个单独的按钮并尝试拖动一个并将其复制到我想要的位置.我只是希望他们留在我放的地方!任何帮助,将不胜感激.

-标记

故事板

模拟器

iphone layout storyboard ios autolayout

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

保存CGContextRef

我有一个绘图应用程序,我想在其中创建一个撤消方法.绘图发生在TouchesMoved:方法中.

我正在尝试创建一个CGContextRef并将其推送到堆栈或将其保存在一个上下文属性中,以后可以恢复,但没有任何运气.任何建议都会很棒.这是我的......

UIImageView      *drawingSurface;
CGContextRef       undoContext;


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 UIGraphicsBeginImageContext(self.view.frame.size);
 CGContextRef context = UIGraphicsGetCurrentContext();
 [drawingSurface.image drawInRect:CGRectMake(0, 0, drawingSurface.image.size.width, drawingSurface.image.size.height)]; 
 UIGraphicsPushContext(context);

        // also tried but cant figure how to restore it
        undoContext = context;

 UIGraphicsEndImageContext();
}
Run Code Online (Sandbox Code Playgroud)

然后我有一个由我的撤销按钮触发的方法......

- (IBAction)restoreUndoImage {
 UIGraphicsBeginImageContext(self.view.frame.size);
 UIGraphicsPopContext();
 drawingSurface.image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我相信我的drawingSurface被指定为nil,因为它只是删除了图像中的所有内容.

我的猜测是我不能用pop这样推.但我似乎无法弄清楚如何只保存上下文然后将其推回到drawingSurface上.Hmmmm.任何帮助都会......嗯......乐于助人.提前致谢 -

并且,仅供参考,这是我正在做的绘制到屏幕,这是很好的工作.这是在我的TouchesMoved中:

 UIGraphicsBeginImageContext(self.view.frame.size);
 CGContextRef context = UIGraphicsGetCurrentContext();
 [drawingSurface.image drawInRect:CGRectMake(0, 0, drawingSurface.image.size.width, drawingSurface.image.size.height)]; 

 CGContextSetLineCap(context, kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
 CGContextSetLineWidth(context, self.brush.size); // for size

 CGContextSetStrokeColorWithColor (context,[currentColor CGColor]);

 CGContextBeginPath(context);
 CGContextMoveToPoint(context, lastPoint.x, lastPoint.y); …
Run Code Online (Sandbox Code Playgroud)

objective-c uiview cgcontext quartz-2d

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

将UIColor作为参数传递时崩溃

我有一个小的UIView对象CircleColorView.m,它只是创建一个带有彩色圆圈的视图。然后,我将该视图用作一堆按钮(所有不同颜色)的背景。

我的问题发生在调用drawRect:方法时。当我引用对象颜色(即UIColor)时,会崩溃,但仅在某些情况下会崩溃。

我很迷茫。这是我的UIView:

ColorCircleView.h

#import <UIKit/UIKit.h>
#import "Constants.h"

@interface CircleColorView : UIView {

    UIColor *color;

}

@property (nonatomic, retain) UIColor *color;

- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)circleColor;

@end
Run Code Online (Sandbox Code Playgroud)

这是ColorCircleView.m

#import "CircleColorView.h"


@implementation CircleColorView
@synthesize color;

- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)circleColor {
    if ((self = [super initWithFrame:frame])) {
        color = [UIColor colorWithCGColor:[circleColor CGColor]];

                // have also tried
                // color = circleColor;


    }

    return self;
}


- (void) drawRect: (CGRect) aRect
{
    CGFloat iconSize = self.frame.size.width;

        // Create a new path
    CGContextRef context = UIGraphicsGetCurrentContext(); …
Run Code Online (Sandbox Code Playgroud)

iphone uiview uicolor

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

WatchKit强制菜单自定义图标模糊

我正在为WatchKit Force Menu创建自定义图标.文档说使用80 x 80大小的图像,绘图区域为54px square.一切正常,但是我的图像在按钮中显示时,与内置按钮图像相比看起来非常模糊.

我在Illustrator中以80px的平方正在创建它们.像文档说的那样保存为.png图像.以72 dpi保存时,大小调整是正确的.如果我做了更高的操作,则会导致按钮中的图像太大.我找不到缩放图像的方法.

有没有人碰到这个?好像我想在这里使用更高分辨率的图像或矢量图形.

iphone ios watchkit

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