我有这样的情况:
如果我单击左脚按钮,我希望我在第二个控制器中的视图显示左脚图像,如果我单击右键,视图应该显示右脚图像。
在第一个控制器中,我写了这个来选择右或左:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
RSViewController *vc = [segue destinationViewController];
if ([[segue identifier] isEqualToString:@"Left-Foot"])
[vc setLeft:YES];
else
[vc setLeft:NO];
}
在第二个控制器中,我有一个设置布尔值的方法
- (void)setLeft:(BOOL)left
{
if (left) {
_left = left;
NSLog(@"LEFT UPDATED IN RSVIEWCONTROLLER");
}else {
_left = left;
NSLog(@"RIGHT UPDATED IN RSVIEWCONTROLLER");
}
}
在同一个控制器中,我使用我的一个 init 在 viewdidload 中创建视图:
- (void)viewDidLoad
{
NSLog(@"meeeea");
[super viewDidLoad];
CGRect rect = CGRectMake(0, 0, 100, 100);
self.animatedCircleView = [[RSAnimatedCircleView alloc] initWithFrameFoot:rect foot:YES];
NSLog(@"Viewdidnoload");
}
在我看来(图中的蓝色小矩形):
- (void)setup:(BOOL)left
{
self.leftFoot = left;
}
- (void)setLeftFoot:(BOOL)leftFoot
{
_leftFoot = leftFoot;
}
- (void)awakeFromNib
{
[self setup:_leftFoot];
}
- (id)initWithFrameFoot:(CGRect)frame foot:(BOOL)left
{
self = [super initWithFrame:frame];
[self setup:left];
self.leftFoot = left;
if (self.leftFoot)
NSLog(@"Left == TRUE");
return self;
}
- (RSFootView *)footView
{
CGRect rect = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
if (self.leftFoot) {
NSLog(@"Now left is yes");
}else {
NSLog(@"left is no");
}
_footView = [[RSFootView alloc] initWithFrame:rect withLeftFoot:self.leftFoot];
[_footView setBackgroundColor:[UIColor clearColor]];
return _footView;
}
- (void)drawRect:(CGRect)rect
{
if (self.leftFoot)
NSLog(@"left ada");
else
NSLog(@"right masd");
CGFloat x = self.bounds.size.height;
CGFloat y = self.bounds.size.width;
CGFloat radius = x/2 - 15;
CGPoint center = CGPointMake(x/2, y/2);
CGFloat startAngle = DEGREES_TO_RADIANS(START_ANGLE);
CGFloat endAngle = DEGREES_TO_RADIANS(END_ANGLE);
// Drawing the sector
UIBezierPath *sector = [UIBezierPath bezierPathWithArcCenter:center
radius:radius
startAngle:startAngle
endAngle:endAngle
clockwise:YES];
sector.lineWidth = 4;
[[UIColor grayColor] setStroke];
[sector stroke];
[self setBackgroundColor:[UIColor clearColor]];
[sector addClip];
[self addSubview:self.footView];
}
在“drawRect”方法中,左脚的值总是假的。我不知道为什么会这样......有人可以帮助我吗?
谢谢