1

我最近升级到了适用于 iOS5 的最新 SDK,并且遇到了我设置的 UIScrollView 的问题。滚动视图的大小取决于我要显示的对象数量,并以编程方式向其中添加对象。我遇到的问题是它正在初始化具有偏移量的加载滚动视图,即使我有代码: [scrollViewObj setContentOffset:CGPointZero];

我还在最后将内容偏移坐标发送到控制台,它确实注册了 (0, 0),但由于某种原因,UI 只是没有选择它。

iOS 5 中是否有一些新的东西使它停止工作?

我的代码如下:

    Code:

    -(void)loadKeyParticipants:(ItineraryItem *)itinerary
    {
// Reset the scroll view back to initial position
//keyParticipants.contentOffset = CGPointZero;


[keyParticipants setContentOffset:CGPointZero];


// clean up scroll view from previous use
while([[keyParticipants subviews] count] > 0)
    [[[keyParticipants subviews] objectAtIndex:0] removeFromSuperview];

// Defined number of frames for key participant scroll view
int numOfFrames = [[itinerary keyParticipantList] count];
keyParticipants.contentSize=CGSizeMake(PARTICIPANT_LIST_X_OFFSET*numOfFrames,208);    



int i;
for (i = 0; i < [[itinerary keyParticipantList] count]; i++)
{
    KeyParticipant *tempParticipant = [[itinerary keyParticipantList] objectAtIndex:i];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex: 0];    

    NSString *docFile = [docDir stringByAppendingPathComponent: [tempParticipant participantPictureFile] ];

    // Insert participant picture
    // textOffsetFromMissingPic is used to shift the text to the right
    // of the picture to left-align to fill up the space of a missing
    // picture
    UIImage *image1;
    int textOffsetFromMissingPic = 0;
    if([[tempParticipant participantPictureFile] isEqualToString:@""])
    {
        // To re-enable shadow image, uncomment first line, and set 
        // second line to 0
        //image1=[UIImage imageNamed: @"blank-profile-md.png"];
        textOffsetFromMissingPic = -157;
    }
    else
    {
        image1=[[UIImage alloc] initWithContentsOfFile:docFile];
        UIImageView *tempImageView = [[UIImageView alloc] initWithImage:image1];        
        tempImageView.frame=CGRectMake(PARTICIPANT_LIST_X_OFFSET*i,0,152,108);
        tempImageView.contentMode=UIViewContentModeScaleAspectFit;
        [self.keyParticipants addSubview:tempImageView];

        textOffsetFromMissingPic = 0;
    }

    // Insert participant names/title
    UILabel *label1=[[UILabel alloc] initWithFrame:CGRectMake(textOffsetFromMissingPic + PARTICIPANT_LIST_X_OFFSET*i+161, 2, 456, 27)];

    // Generate approptiate name header with salutation and title conditionally
    // if they are available
    NSString *fullParticipantHeading = @"";

    if([tempParticipant participantSalutation] != nil)
        fullParticipantHeading = [NSString stringWithFormat:@"%@ %@", [tempParticipant participantSalutation], [tempParticipant participantName]];
    else
        fullParticipantHeading = [tempParticipant participantName];

    if([tempParticipant participantTitle] != nil)
        fullParticipantHeading = [NSString stringWithFormat:@"%@, %@", fullParticipantHeading, [tempParticipant participantTitle]];

    // Populate label for name header        
    [label1 setText:fullParticipantHeading];
    [label1 setBackgroundColor:[UIColor clearColor]];
    label1.font = [UIFont fontWithName:@"Helvetica" size: 24.0];
    label1.font = [UIFont boldSystemFontOfSize:24.0];
    label1.textColor = [UIColor colorWithRed:0 green:0 blue:255 alpha:255];
    [self.keyParticipants addSubview:label1];

    // Insert contact information
    UITextView *textView1=[[UITextView alloc] initWithFrame:CGRectMake(textOffsetFromMissingPic + PARTICIPANT_LIST_X_OFFSET*i+153, 28, 508, 29)];
    [textView1 setText:[tempParticipant participantContact]];
    [textView1 setBackgroundColor:[UIColor clearColor]];
    textView1.font = [UIFont fontWithName:@"Helvetica" size:14.0];
    textView1.editable=NO;
    textView1.scrollEnabled=NO;
    textView1.dataDetectorTypes=UIDataDetectorTypeAll;
    [self.keyParticipants addSubview:textView1];

    // CHANGED: Participant Role - Company Name
    UILabel *meetingNameLabel=[[UILabel alloc] initWithFrame:CGRectMake(textOffsetFromMissingPic + PARTICIPANT_LIST_X_OFFSET*i+161, 51, 503, 27)];       
    [meetingNameLabel setText:[NSString stringWithFormat:@"%@ - %@", [tempParticipant role], [tempParticipant companyName]]];
    [meetingNameLabel setBackgroundColor:[UIColor clearColor]];
    meetingNameLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];
    [self.keyParticipants addSubview:meetingNameLabel];

    // Insert meeting time
    UILabel *meetingTimeLabel=[[UILabel alloc] initWithFrame:CGRectMake(textOffsetFromMissingPic + PARTICIPANT_LIST_X_OFFSET*i+161, 73, 503, 21)];
    [meetingTimeLabel setText:[tempParticipant meetingTime]];
    meetingTimeLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];
    meetingTimeLabel.textColor = [UIColor darkGrayColor];
    [self.keyParticipants addSubview:meetingTimeLabel];

    // Insert meeting location
    UILabel *meetingLocationLabel=[[UILabel alloc] initWithFrame:CGRectMake(textOffsetFromMissingPic + PARTICIPANT_LIST_X_OFFSET*i+161, 90, 503, 21)];
    [meetingLocationLabel setText:[tempParticipant meetingLocation]];
    meetingLocationLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];
    meetingLocationLabel.textColor = [UIColor darkGrayColor];
    [self.keyParticipants addSubview:meetingLocationLabel];

    // Insert biography
    UITextView *bioTextView=[[UITextView alloc] initWithFrame:CGRectMake(PARTICIPANT_LIST_X_OFFSET*i, 111, 663, 97)];
    [bioTextView setText:[tempParticipant bioText]];
    bioTextView.font = [UIFont fontWithName:@"Helvetica" size:18.0];
    bioTextView.editable=NO;
    [self.keyParticipants addSubview:bioTextView];

    // Insert swipe icon if there's multiple key participants and the page is
    // not the last page
    if( ([[itinerary keyParticipantList] count] > 1) && 
       (i != [[itinerary keyParticipantList] count] - 1))
    {
        UIImage *swipeImage = [UIImage imageNamed: @"swipeIcon.png"];
        UIImageView *swipeImageView = [[UIImageView alloc] initWithImage:swipeImage];        
        swipeImageView.frame=CGRectMake(PARTICIPANT_LIST_X_OFFSET*i+615,0,40,40);
        swipeImageView.contentMode=UIViewContentModeScaleAspectFit;
        [self.keyParticipants addSubview:swipeImageView];
    }
}

NSLog(@"X: %f / Y: %f", [keyParticipants contentOffset].x, [keyParticipants contentOffset].y);
    }
4

0 回答 0