關於ScrollView無法滾動的解決方案

來源:互聯網
上載者:User

標籤:使用   os   io   問題   ar   代碼   size   c   

今天做了一個ScrollView的小例子(我的環境Xcode5 IOS7),結果發現無法滾動,即使設定了scrollView的contentSize還是不行,於是研究了一番,最終找到瞭解決方案: 在ios6之前,因為Xcode沒有Autolayout的機制,所以直接使用scrollView,設定它的contentSize即可正常滾動在ios6之後,因為Xcode引入了Autolayout的機制,所以我們設定的contentSize被修改為適合螢幕大小的值,也就是說自適應啦,因此無法滾動,解決方案如下:直接去掉scrollView的Autolayout即可,但是這種方式不完美,畢竟Autolayout是官方推薦的,輕易去掉會引起其他問題,因此慎用。在viewController中重載 - (void)viewDidAppear:(BOOL)animated 方法,並且設定contentSize,代碼如下:複製代碼 1 #import "ImaginariumViewController.h" 2 3 @interface ImaginariumViewController () 4 @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; 5 @property (weak, nonatomic) IBOutlet UIImageView *imageView; 6 @end 7 8 @implementation ImaginariumViewController 9 10 - (void)viewDidAppear:(BOOL)animated11 {12 [super viewDidAppear:animated];13 self.scrollView.contentSize = self.imageView.image.size;14 self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);15 }16 17 @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.