我有這樣的情況:更新視圖
如果我點擊左腳按鈕,我想,我在第二控制器視圖顯示左腳形象,如果我點擊右鍵,視圖應顯示右腳圖像。
在第一控制器我寫這個選擇左或右:
- (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");
}
在我看來(小藍色的矩形e在圖中):
- (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」中,leftfoot值始終爲false。我不知道爲什麼是這樣的...任何人都可以幫助我嗎?
謝謝