小编nbu*_*urk的帖子

iOS - 核心图形适用于颜色,但不适用于黑色,白色,灰色

我正在使用以下类绘制一个简单的描边圆:

 @implementation StrokedCircle

 - (id)initWithRadius:(CGFloat)radius strokeWidth:(CGFloat)strokeWidth strokeColor:(UIColor *)strokeColor
 {
     self = [super initWithRadius:radius];
     if (self)
     {
         _strokeWidth = strokeWidth;
         _strokeColor  = strokeColor;
     }
     return self;
 }


 - (void)drawRect:(CGRect)rect
 {
     NSLog(@"Drawing with color %@ and stroke width %f", self.strokeColor, self.strokeWidth);

     CGContextRef context = UIGraphicsGetCurrentContext();
     CGRect circleRect = CGRectInset(rect, self.strokeWidth, self.strokeWidth);
     CGContextAddEllipseInRect(context, circleRect);
     CGContextSetLineWidth(context, self.strokeWidth);
     CGContextSetStrokeColor(context, CGColorGetComponents([self.strokeColor CGColor]));
     CGContextStrokePath(context);
 }

 @end
Run Code Online (Sandbox Code Playgroud)

注意:超类是一个简单的圆(子类UIView),其中包含一个radius属性,并且视图的backgroundcolor设置为clearColor.

在视图控制器中,我添加以下代码viewDidLoad:

 - (void)viewDidLoad
 {
     [super viewDidLoad];
     StrokedCircle *strokedCircle = [[StrokedCircle alloc] initWithRadius:50.0 …
Run Code Online (Sandbox Code Playgroud)

core-graphics objective-c cgcontext drawrect ios

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

从NSCoder获取所需的init属性(编码器aDecoder:NSCoder)

我正在Swift中实现一个Circle类(子类UIView),radius它根据传入的帧在其初始化器中设置它,init(frame: CGRect)如下所示:

override init(frame: CGRect)
{
    radius = frame.width/2.0
    super.init(frame: frame)
}
Run Code Online (Sandbox Code Playgroud)

我还想确保从Interface Builder实例化圆圈的情况,所以我还实现了'必需的init(编码器aDecoder:NSCoder)`(我无论如何都被Xcode强制做了).

如何检索frame以某种方式包含在其中的视图的属性aDecoder.我想要实现的基本上是这样的:

required init(coder aDecoder: NSCoder)
{
   var theFrame = aDecoder.someHowRetrieveTheFramePropertyOfTheView // how can I achieve this?
   radius = theFrame.width/2.0
   super.init(coder: aDecoder)
}
Run Code Online (Sandbox Code Playgroud)

objective-c drawrect nscoder ios swift

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

为什么这个C++多态不起作用?

我不明白为什么这种继承不起作用.我有以下设置:

struct Shape{}
struct Stain : Shape {}
Run Code Online (Sandbox Code Playgroud)

现在,为什么我不能做以下事情:

vector<Shape> shapes;
Stain stain();
shapes.push_back(stain);
Run Code Online (Sandbox Code Playgroud)

我希望这可以工作,因为它Stain是一个子类Shape,所以我应该能够Stain进入一个vector<Shape>?或者这在概念上是错误的,我想要做的确实不可能?

c++ polymorphism

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

如何使用反应导航从标题中的按钮“导航”到新屏幕?

我正在使用react-navigation并且要在标题的右侧添加一个按钮,该按钮将导航到其他屏幕。但是在设置时navigationOptions,我想知道如何navigate在按下按钮时调用的回调函数中访问该函数:

const RootNavigationStack = StackNavigator({
  PokemonList: {
    screen: PokemonListWrapper,
    navigationOptions: {
      title: ({state}) => `Pokedex`,
      header: ({ state, setParams }) => {
        return {
          visible: true,
          right: (
            <Button
              title={'Add'}
              onPress={() => // navigate to new screen here
            />
          ),
        }
      }
    },
  },
, {
  headerMode: 'screen'
})
Run Code Online (Sandbox Code Playgroud)

有什么想法可以实现吗?我当时正在考虑使用withNavigation,但仍不清楚如何使用。

javascript reactjs react-navigation

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