Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c iPhone SDK中的自动滚动功能_Objective C_Ios4 - Fatal编程技术网

Objective c iPhone SDK中的自动滚动功能

Objective c iPhone SDK中的自动滚动功能,objective-c,ios4,Objective C,Ios4,我通过遍历示例代码,将自动滚动功能添加到应用程序中。 在这段代码中,我得到了从上到下和从下到上的滚动。但我不想从上到下滚动。我总是只想从下到上滚动。如果我删除toptobttom代码并根据它不工作的情况对其余代码进行更改。有人能帮我吗 -(void)viewdidLoad { infoScrollView = [[UIScrollView alloc]init]; infoScrollView.frame = CGRectMake(0,0,330,270); infoS

我通过遍历示例代码,将自动滚动功能添加到应用程序中。 在这段代码中,我得到了从上到下和从下到上的滚动。但我不想从上到下滚动。我总是只想从下到上滚动。如果我删除toptobttom代码并根据它不工作的情况对其余代码进行更改。有人能帮我吗

-(void)viewdidLoad
{ 
    infoScrollView = [[UIScrollView alloc]init];
    infoScrollView.frame = CGRectMake(0,0,330,270);
    infoScrollView.contentSize = CGSizeMake(100,1000);
    [myInfoView addSubview:infoScrollView];

    scrollingToTop=NO;

    UIImageView *infoImgView = [[UIImageView alloc]initWithFrame:CGRectMake(70,0,200,1000)];
    infoImgView.image = [UIImage imageNamed:@"lepke-tar2.png"];
    [infoScrollView addSubview:infoImgView];

    infoScrollView.delegate = self;
    if (infoScrollView.contentSize.height>infoScrollView.frame.size.height) 
    {
        [infoScrollView scrollRectToVisible:CGRectMake(0, infoScrollView.contentSize.height-infoScrollView.frame.size.height, infoScrollView.frame.size.width, infoScrollView.frame.size.height) animated:NO];

    }
    [self performSelector:@selector(scrollToTop) withObject:nil afterDelay:0.5];
    [myInfoView addSubview:infoScrollView];


    UIButton* infocancelBttn = [[UIButton alloc ]initWithFrame:CGRectMake(295,-8,45,45)];
    [infocancelBttn setImage:[UIImage imageNamed:@"cancel_icon.png"] forState:UIControlStateNormal];
    [infocancelBttn addTarget:self action:@selector(infoViewCloseAction) forControlEvents:UIControlEventTouchUpInside];
    [myInfoView addSubview:infocancelBttn];
    [infocancelBttn release];


}

-(void)viewDidAppear:(BOOL)animated
{
    [infoScrollView scrollRectToVisible:CGRectMake(0, 0, infoScrollView.frame.size.width, infoScrollView.frame.size.height+200) animated:YES];
}


- (void) scrollToTop
{
    scrollingToTop=YES;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:10.0];
    //[self.scrollView scrollRectToVisible:CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height) animated:YES];
    [infoScrollView setContentOffset:CGPointMake(0,-300)];

    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(scroll)];

    [UIView commitAnimations];
}

-(void) scroll
{
    if (scrollingToTop==YES) 
    {
        [self performSelector:@selector(scrollToBottom) withObject:nil afterDelay:1.0];
    }
    else
    {
        [self performSelector:@selector(scrollToTop) withObject:nil afterDelay:1.0];
    }

}

- (void)scrollToBottom
{
    scrollingToTop=NO;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:10.0];
    [infoScrollView setContentOffset:CGPointMake(0,infoScrollView.contentSize.height-infoScrollView.frame.size.height)animated:NO];

    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(scroll)];

    [UIView commitAnimations];  
}

我认为你的if陈述是错误的:

-(void) scroll
{
    if (scrollingToTop==YES) 
    {
        [self performSelector:@selector(scrollToBottom) withObject:nil afterDelay:1.0];
    }
    else...
如果删除scrollToBottom方法,代码将失败。

您应该将此更改为
[自执行选择器:@选择器(scrollToTop),对象:nil afterDelay:1.0]
因为你在问ScrollingTop是否为真