我正在製作日曆視圖日曆,就像本機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