I am newbie on IOS developing. I try to write my own custom class to do some 2d stuff. (TwoDOperations.h and TwoDOperations.m). Below are my files.
--------TwoDOperations.h------
@interface TwoDOperations : UIView
- (void)drawRect:(CGRect)rect withscene:(UIViewController *)sender;
- (void)drawRectV2:(CGRect)rect;
-(instancetype)init;
@end
--------TwoDOperations.m------
#import "TwoDOperations.h"
@implementation TwoDOperations
-(instancetype)init{
self=[super init];
if (self)
{
}
return self;
}
- (void)drawRect:(CGRect)rect withscene:(UIViewController *)sender{
UIView *myBox = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 300, 10)];
myBox.backgroundColor = [UIColor lightGrayColor];
[sender.view addSubview:myBox];
}
- (void)drawRectV2:(CGRect)rect{
UIBezierPath *circle = [UIBezierPath
bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];
UIGraphicsBeginImageContext(CGSizeMake(200, 200));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor lightGrayColor].CGColor);
[circle fill];
[circle stroke];
}
@end
as you see I have two methods to do some 2d things.
and my main methods like this
TwoDOperations *twoD = [[TwoDOperations alloc]init];
CGRect rect = CGRectMake(10,10,10,10);
[twoD drawRect:rect withscene:self];
[twoD drawRectV2:rect];
(I know rect is not used for now)
when I use <twoD drawRect:rect with scene:self> it is successfully drawing. I can draw a rectangle. But when I use <twoD drawRectV2:rect> it is nothing. It doesn't draw anything? I check in debug mode and I find context is not null. I ask simply why?
Aucun commentaire:
Enregistrer un commentaire