以编程方式使 uitextview 滚动

2023-10-23移动开发问题
5

本文介绍了以编程方式使 uitextview 滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想让我的 uitextview 在应用程序启动时自动滚动.谁能帮我详细的代码?我是 iPhone SDK 的新手.

I want to make my uitextview to scroll automatically whenever the application is launched. Can anyone help me with a detailed code? I am new to iPhone SDK.

推荐答案

.h文件

@interface Credits : UIViewController 
{
    NSTimer *scrollingTimer;

    IBOutlet UITextView *textView;


}
@property (nonatomic , retain) IBOutlet UITextView *textView;

- (IBAction) buttonClicked ;

- (void) autoscrollTimerFired;

@end

.m 文件

- (void) viewDidLoad
{       
    // it prints the initial position of text view 
    NSLog(@"%f %f",textView.contentSize.width , textView.contentSize.height);

    if (scrollingTimer == nil)
    {
        // A timer that updates the content off set after some time so it can scroll 
        // you can change time interval according to your need (0.06)
        // autoscrollTimerFired is the method that will be called after specified time interval. This method will change the content off set of text view
        scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:(0.06)
                         target:self selector:@selector(autoscrollTimerFired) userInfo:nil repeats:YES];        
    }
}

- (void) autoscrollTimerFired
{
    CGPoint scrollPoint = self.textView.contentOffset; // initial and after update
    NSLog(@"%.2f %.2f",scrollPoint.x,scrollPoint.y);
    if (scrollPoint.y == 583) // to stop at specific position 
    {
        [scrollingTimer invalidate];
        scrollingTimer = nil;
    }
    scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1); // makes scroll
    [self.textView setContentOffset:scrollPoint animated:NO];
    NSLog(@"%f %f",textView.contentSize.width , textView.contentSize.height);

}

希望对你有帮助....

Hope it helps you....

这篇关于以编程方式使 uitextview 滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7