2

一些背景。我正在帮助我儿子学校的一群学生,他们想编写一个简单的跟踪应用程序来管理将在 iPod Touch 上使用的学生观察结果。

我只使用标准小部件完成了非常基本的 iOS 开发,但我很乐意提供帮助。

我们完成并设计了应用程序的功能和界面,现在开始编程。我无法理解的地方是,他们希望在屏幕底部有一个条带,每天作为一个小块显示日期和日期,以及一个指示器来显示当天是否有观察。

我希望你们能指出我正确的方向,无论是现有的小部件还是详细解释如何实现这一点。我尝试了几种方法,但都没有运气。

我很感激这方面的任何帮助,因为我知道这一定是一个常见的要求,但我正在努力解决这个问题。

4

2 回答 2

5

我想我会发布我的最终解决方案,以防其他人发现它有用。

在视图根视图控制器中,我添加了一个自定义 UITableViewController,它基本上将表格旋转 90 度,然后将每个表格单元格旋转 -90 度。它做我想要的非常简单。

根视图控制器的代码。这设置了表格的大小和位置:

scrollingDateViewController=[[ScrollingDateViewController alloc] initWithNibName:@"ScrollingDateView" bundle:[NSBundle mainBundle]];
CGRect rect=CGRectMake(0,330,320,100);    
scrollingDateViewController.view.frame=rect;
scrollingDateViewController.view.backgroundColor=[UIColor clearColor];
scrollingDateViewController.delegate = self;
[self.view addSubview:scrollingDateViewController.view];

ScrollingDateViewController 的关键代码。这会将表格旋转 90 度,每个单元格旋转 -90 度:

- (void)viewDidLoad {
today = [[NSDate alloc] init];    
CGRect rect=self.view.frame;
myTableView.frame=rect;
myTableView.layer.transform = CATransform3DRotate(CATransform3DIdentity,1.57079633,0,0,1);
myTableView.backgroundColor=[UIColor clearColor];
myTableView.separatorColor=[UIColor clearColor];
myTableView.frame=rect;
myTableView.rowHeight=44;  // cellWidth
myTableView.showsHorizontalScrollIndicator=NO;
myTableView.showsVerticalScrollIndicator=NO;
myTableView.separatorColor=nil;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"tableCell"];
if(!cell){
    cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tableCell"];
    cell.contentView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"cell_back.png"]];
    cell.contentView.transform =  CGAffineTransformMakeRotation(-1.57079633);
    cell.selectionStyle=UITableViewCellSelectionStyleGray;

    // Add background image view
    CGRect rect=CGRectZero;
    UIImageView *imgView=[[UIImageView alloc] initWithFrame:rect];
    imgView.contentMode=UIViewContentModeScaleToFill;
    imgView.layer.transform = CATransform3DRotate(CATransform3DIdentity,-1.57079633,0,0,1);
    imgView.tag=101;
    [cell addSubview:imgView];

    rect.origin.x=0;
    rect.origin.y=0;
    rect.size.height=80;
    rect.size.width=44;
    imgView.frame=rect;
    [imgView release];

    // Add Day Label
    UILabel *dayLabel=[[UILabel alloc] initWithFrame:rect];
    dayLabel.layer.transform = CATransform3DRotate(CATransform3DIdentity,-1.57079633,0,0,1);
    dayLabel.tag=102;
    dayLabel.font = [UIFont fontWithName:@"Geogrotesque-Medium" size:14.0];
    dayLabel.textAlignment=UITextAlignmentCenter;
    dayLabel.backgroundColor=[UIColor clearColor];
    dayLabel.textColor=[UIColor darkGrayColor];

    [cell addSubview:dayLabel];
    rect.origin.x=40;
    rect.origin.y=0;
    rect.size.height=44;
    rect.size.width=20;
    dayLabel.frame=rect;
    [dayLabel release];

    // Add Date Label
    UILabel *dateLabel=[[UILabel alloc] initWithFrame:rect];
    dateLabel.layer.transform = CATransform3DRotate(CATransform3DIdentity,-1.57079633,0,0,1);
    dateLabel.tag=103;
    dateLabel.font = [UIFont fontWithName:@"Geogrotesque-Bold" size:18.0 ];
    dateLabel.textAlignment=UITextAlignmentCenter;
    dateLabel.backgroundColor=[UIColor clearColor];
    dateLabel.textColor=[UIColor darkGrayColor];

    [cell addSubview:dateLabel];
    rect.origin.x=55;
    rect.origin.y=0;
    rect.size.height=44;
    rect.size.width=20;
    dateLabel.frame=rect;

    [dateLabel release];
}

UILabel *label=(UILabel*)[cell viewWithTag:102];
label.text= [self getDayString:displayDate];
label=(UILabel*)[cell viewWithTag:103];
label.text= [self getDateString:displayDate];
return cell;

}
于 2011-11-17T06:48:23.233 回答
1

恕我直言,您应该创建一个要在每个日期显示的视图。创建类似的东西

@interface DayView : UIView {

您可以使用 nib 实现它,或者在 drawRect 方法中以编程方式制作所有内容。

之后转到您的 Xcode 文档并搜索 UIScrollView。Xcode 将为您提供代码示例,使用项目“Scrolling”来了解如何使用 scrollView。在这个示例中,他们滚动图片,您将它们替换为我们的自定义 DayView。

祝你好运!

于 2011-10-21T06:05:37.043 回答