简体   繁体   中英

UITextView scroll (Automatically) in iPhone?

I am working in iPhone application, Using UITextView to show multiple text inside it, when the user tab the screen, automatically scroll UITextView content from bottom to top (scrolling level slow) and its working fine, i want to increase scroll speed like 1,2,3,4,5,6...10, How to do this? Please help me.

Thanks in advance

I tried this:

     - (void)viewDidLoad
    {
        [super viewDidLoad];

        ScriptDetails = [[UITextView alloc]initWithFrame:CGRectMake(0,9,480,285)];
        ScriptDetails.text=Script;
        ScriptDetails.textAlignment=UITextAlignmentLeft;
        ScriptDetails.editable=NO;
        ScriptDetails.delegate=self;
        ScriptDetails.font=[UIFont fontWithName:str1 size:f];
        ScriptDetails.backgroundColor=tColor1;
        ScriptDetails.textColor=tColor;
        [self.view addSubview:ScriptDetails];

     UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(TouchToPlay)] autorelease];
    singleTap.delegate=self;
    singleTap.numberOfTapsRequired = 1; 
    [ScriptDetails addGestureRecognizer:singleTap];
    }

-(void)TouchToPlay
{
    NSLog(@"single");  

  timer = [NSTimer scheduledTimerWithTimeInterval:(35.0/1000.0)
                                                   target:self
                                                 selector:@selector(autoscrollTimerFired:) 
                                                 userInfo:nil 
                                                  repeats:YES];

}



- (void)autoscrollTimerFired:(NSTimer*)timer 
{
    CGPoint scrollPoint = ScriptDetails.contentOffset;
    scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1);
    [ScriptDetails setContentOffset:scrollPoint animated:NO];
}

If its just about scrolling fast, you can minimize the time at which the timer function is called. And for scrolling slow, you can increase the time.

Let me know if you are looking for something else.

The other way is to put the variable in - (void)autoscrollTimerFired:(NSTimer*)timer method in scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1); line instead of just 1 put there some iVar instead and provide some mechanism for like say one + and - button to increase and decrease the speed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM