UIScrollView常見屬性,uiscrollview屬性

來源:互聯網
上載者:User

UIScrollView常見屬性,uiscrollview屬性
什麼是UIScrollView•裝置的螢幕大小是極其有限的,因此直接展示在使用者眼前的內容也相當有限••當展示的內容較多,超出一個螢幕時,使用者可通過滾動手勢來查看螢幕以外的內容••普通的UIView不具備滾動功能,不能顯示過多的內容••UIScrollView是一個能夠滾動的視圖控制項,可以用來展示大量的內容,並且可以通過滾動查看所有的內容

 

•舉例:手機上的“設定”、其他樣本程式•如果UIScrollView無法滾動,可能是以下原因:Ø沒有設定contentSizeØscrollEnabled = NOØ沒有接收到觸摸事件:userInteractionEnabled = NOØ沒有取消autolayout功能(要想scrollView滾動,必須取消autolayout)Ø……UIScrollView的常見屬性•@property(nonatomic) CGPoint contentOffset;Ø這個屬性用來表示UIScrollView滾動的位置

 

•@property(nonatomic) CGSize contentSize;Ø這個屬性用來表示UIScrollView內容的尺寸,滾動範圍(能滾多遠)••@property(nonatomic) UIEdgeInsets contentInset;Ø這個屬效能夠在UIScrollView的4周增加額外的捲動區域 具體代碼實現

Main.storyboard

這裡添加按鈕的話,不能添加在Scoll View裡面

#import "ViewController.h"

 

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

- (IBAction)btn;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    //滾動的範圍

    self.scrollView.contentSize=self.imageView.frame.size;

    //滾動的外邊距

    self.scrollView.contentInset=UIEdgeInsetsMake(10, 20, 30, 40);

    

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

  

    

}

 

- (IBAction)btn {

    //中心點座標

    CGPoint offest=CGPointMake(100, 100);

//    CGPoint offest=self.scrollView.contentOffset;

//    offest.x+=100;

//    offest.y+=100;

    [self.scrollView setContentOffset:offest animated:YES];

    

}

@end

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.