Objective c 指定了UIScrollView与UIProgressView的滚动

Objective c 指定了UIScrollView与UIProgressView的滚动,objective-c,scroll,scrollview,progress,uiprogressview,Objective C,Scroll,Scrollview,Progress,Uiprogressview,我想在导航栏下添加一个进度条,它将指示UIScrollView滚动的进度,我使用(不工作):我使用 现在检查我创建了一个演示: #import "ViewController.h" @interface ViewController ()<UIScrollViewDelegate>{ UIScrollView *scroll; UIProgressView *indicater; } @end

我想在导航栏下添加一个进度条,它将指示UIScrollView滚动的进度,我使用(不工作):我使用


现在检查我创建了一个演示:

       #import "ViewController.h"

    @interface ViewController ()<UIScrollViewDelegate>{
        UIScrollView *scroll;
        UIProgressView *indicater;
        }
    @end

    @implementation ViewController



    - (void)viewDidLoad {
        indicater=[[UIProgressView alloc]initWithFrame:CGRectMake(0, 65, 320,10)];
        indicater.backgroundColor=[UIColor redColor];
        indicater.progress = 0.0;
        indicater.hidden=false;


        [self.view addSubview:indicater];

        scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(10, 80,300, 200)];
        scroll.backgroundColor=[UIColor greenColor];
        scroll.userInteractionEnabled=YES;
        scroll.delegate=self;
        scroll.contentSize = CGSizeMake(300 ,5000);

        [self.view addSubview:scroll];



    }
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{

        CGPoint offset = scroll.contentOffset;
        CGRect bounds = scroll.bounds;
        CGSize size = scroll.contentSize;
        UIEdgeInsets inset = scroll.contentInset;
        float y = offset.y + bounds.size.height - inset.bottom;
        float h = size.height;
        NSLog(@"%f",y);
        NSLog(@"%f",h);
        NSNumber *num=[NSNumber numberWithFloat:y];
        NSNumber *num1=[NSNumber numberWithFloat:h];



    [self UpdateProgressbar:num TotalscrollLenrth:num1];

}

-(void)UpdateProgressbar:(NSNumber*)currentscrollLenrth TotalscrollLenrth:(NSNumber*)n
{

    NSString *totalLength = [NSString stringWithFormat:@"%@", n];
    NSLog(@"%@", totalLength);

    NSString *currentScrool = [NSString stringWithFormat:@"%@", currentscrollLenrth];
    NSLog(@"%@", currentScrool);
    if (currentscrollLenrth <= n) {
        [indicater setProgress:([currentScrool intValue]/[totalLength floatValue])];
    }
    else {
                  // do somithig

    }
}
#导入“ViewController.h”
@界面视图控制器(){
UIScrollView*滚动;
UIProgressView*指示器;
}
@结束
@实现视图控制器
-(无效)viewDidLoad{
指示符=[[UIProgressView alloc]initWithFrame:CGRectMake(0,65320,10)];
指示剂。背景色=[UIColor REDCLOR];
指标。进度=0.0;
指示符。隐藏=假;
[self.view addSubview:indicater];
scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(108300200)];
scroll.backgroundColor=[UIColor-greenColor];
scroll.userInteractionEnabled=YES;
scroll.delegate=self;
scroll.contentSize=CGSizeMake(3005000);
[self.view addSubview:滚动];
}
-(无效)scrollViewDidScroll:(UIScrollView*)scrollView{
CGPoint offset=scroll.contentOffset;
CGRect bounds=scroll.bounds;
CGSize size=scroll.contentSize;
UIEdgeInsets inset=scroll.contentInset;
浮动y=偏移量.y+bounds.size.height-插入底部;
浮动h=尺寸。高度;
NSLog(@“%f”,y);
NSLog(@“%f”,h);
NSNumber*num=[NSNumber numberWithFloat:y];
NSNumber*num1=[NSNumber numberWithFloat:h];
[self-UpdateProgressbar:num TotalscrollLenrth:num1];
}
-(void)UpdateProgressbar:(NSNumber*)currentscrollLenrth TotalscrollLenrth:(NSNumber*)n
{
NSString*总长度=[NSString stringWithFormat:@“%@”,n];
NSLog(@“%@”,总长度);
NSString*currentScrool=[NSString stringWithFormat:@“%@”,currentscrollLenrth];
NSLog(@“%@”,currentScrool);

如果(currentscrollLenrth)是的,这是可能的……如果你这样问,你会得到选票…………如果你面临任何问题,你需要尝试一下……请在这里发布……不要问信息我想把这个问题放在上面hold@NAVEENKUMAR确切地说,我对此有问题,我会-(void)scrollViewDidScroll:(UIScrollView*)scrollView{self.progressView.progress=scrollView.contentOffset.y;}但它不起作用您不能只分配
contentOffset.y
,进度从值
(0-1)
开始工作您的值应该介于这两者之间。
       #import "ViewController.h"

    @interface ViewController ()<UIScrollViewDelegate>{
        UIScrollView *scroll;
        UIProgressView *indicater;
        }
    @end

    @implementation ViewController



    - (void)viewDidLoad {
        indicater=[[UIProgressView alloc]initWithFrame:CGRectMake(0, 65, 320,10)];
        indicater.backgroundColor=[UIColor redColor];
        indicater.progress = 0.0;
        indicater.hidden=false;


        [self.view addSubview:indicater];

        scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(10, 80,300, 200)];
        scroll.backgroundColor=[UIColor greenColor];
        scroll.userInteractionEnabled=YES;
        scroll.delegate=self;
        scroll.contentSize = CGSizeMake(300 ,5000);

        [self.view addSubview:scroll];



    }
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{

        CGPoint offset = scroll.contentOffset;
        CGRect bounds = scroll.bounds;
        CGSize size = scroll.contentSize;
        UIEdgeInsets inset = scroll.contentInset;
        float y = offset.y + bounds.size.height - inset.bottom;
        float h = size.height;
        NSLog(@"%f",y);
        NSLog(@"%f",h);
        NSNumber *num=[NSNumber numberWithFloat:y];
        NSNumber *num1=[NSNumber numberWithFloat:h];



    [self UpdateProgressbar:num TotalscrollLenrth:num1];

}

-(void)UpdateProgressbar:(NSNumber*)currentscrollLenrth TotalscrollLenrth:(NSNumber*)n
{

    NSString *totalLength = [NSString stringWithFormat:@"%@", n];
    NSLog(@"%@", totalLength);

    NSString *currentScrool = [NSString stringWithFormat:@"%@", currentscrollLenrth];
    NSLog(@"%@", currentScrool);
    if (currentscrollLenrth <= n) {
        [indicater setProgress:([currentScrool intValue]/[totalLength floatValue])];
    }
    else {
                  // do somithig

    }
}