我正在制作日历视图日历,就像本机iPhone日历一样。如果它们的大小和时间相同,我试图将它们放在本地日历中并排放置。iOS:多个相交视图
但是,我只能弄清楚如何做到2瓦,而不是多瓦。在附图中我有4块瓷砖。一个稍微扩展到另一个3.然后,我有第一块瓷砖在最左边,第二块瓷砖在第一块瓷砖旁边。现在我需要弄清楚如何添加额外的瓷砖?
我该怎么做超过2个瓷砖?
关于形象:如果你不能看到它的第三瓷砖是ontop的第2瓦(你可以看到它是有点暗,因为他们是在彼此顶部
。- (void)layoutSubviews
{
// Set the main
for (UIView *view in self.subviews) {
APCalendarDayTile *tile = (APCalendarDayTile *)view;
CGFloat startPos = [APCalendarCurrentDayView yAxisForTime:[APCalendarCurrentDayView minutesToTime:tile.appointment.startDate]];
CGFloat endPos = [APCalendarCurrentDayView yAxisForTime:[APCalendarCurrentDayView minutesToTime:tile.appointment.endDate]];
tile.frame = CGRectMake(kLeftSideBuffer, startPos, (self.bounds.size.width - kLeftSideBuffer) , endPos - startPos);
tile.backgroundColor = [UIColor colorWithHexString:tile.appointment.appointmentColor];
}
for (UIView *view in self.subviews) {
APCalendarDayTile *tile = (APCalendarDayTile *)view;
if ([self viewIntersectsWithAnotherView:tile]) {
}
}
}
- (BOOL)viewIntersectsWithAnotherView:(UIView*)selectedView{
NSArray *subViewsInView=[self subviews];// I assume self is a subclass
// of UIViewController but the view can be
//any UIView that'd act as a container
//for all other views.
for (UIView *theView in subViewsInView){
if (![selectedView isEqual:theView]) {
if(CGRectIntersectsRect(selectedView.frame, theView.frame)) {
if ((selectedView.frame.origin.y == theView.frame.origin.y) && (selectedView.frame.size.height == theView.frame.size.height)) {
if (theView.frame.size.width == self.bounds.size.width - kLeftSideBuffer) {
theView.frame = CGRectMake(theView.frame.origin.x, selectedView.frame.origin.y, theView.frame.size.width/2, selectedView.frame.size.height);
}
selectedView.frame = CGRectMake(theView.frame.origin.x + theView.frame.size.width, selectedView.frame.origin.y, theView.frame.size.width, selectedView.frame.size.height);
return YES;
}
}
}
}
return NO;
}
不,我说得对。我只想要同时开始并且长度相同的并排 – Bot 2012-03-14 22:20:21
您的if/else似乎有点混乱。 – Bot 2012-03-15 16:33:57