iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
csmx123
V2EX  ›  iDev

xcode 6 beta 4 ScrollViewDelegate 中 scrollViewWillEndDragging 无法修改 targetContentOffset 的值

  •  
  •   csmx123 · Aug 3, 2014 · 5036 views
    This topic created in 4327 days ago, the information mentioned may be changed or developed.

    如题,本人正在写一个iOS app,并且希望在左右滑动一个UIScrollView以后根据滑动的offset大小定义targetContentOffset。语言是swift,编译环境是xcode 6 beta 4。

    部分代码:

    class someViewController: UIViewController, UIScrollViewDelegate {
    
    func someMethod() {
          ...
          var myScrollView = UIScrollView()
          ...
          myView.addSubview( myScrollView )
          myScrollView.delegate = self
    }
    
    func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: UnsafePointer<CGPoint>) {
    
         if scrollView.contentOffset.x > someValue {
               println("something")
               targetContentOffset.memory.x = -20
               println("\(targetContentOffset.memory.x)")
         }
    }
    
    }
    

    得到的结果是 something 被输出了,targetContentOffset.memory.x的值也被修改了,但是view没有停留到我想让他停留的位置。请高手来看一看怎么回事。谢谢。

    3 replies    2014-08-04 11:32:49 +08:00
    run2
        1
    run2  
       Aug 3, 2014
    contentSize 不够大?瞎猜的-。-
    csmx123
        2
    csmx123  
    OP
       Aug 4, 2014
    更新:

    func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: UnsafePointer<CGPoint>) {

    if scrollView.contentOffset.x > someValue {

    targetContentOffset.memory.x = -20
    scrollView.setContentOffset( CGPointMake( -20.0 , 0.0 ), animated: false )
    }
    }

    }

    实现了自动滑动,但是当animated变成true的时候自动滑动失败了
    csmx123
        3
    csmx123  
    OP
       Aug 4, 2014
    以解决,删除了storyboard,用纯代码实现就没问题了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1101 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 23:26 · PVG 07:26 · LAX 16:26 · JFK 19:26
    ♥ Do have faith in what you're doing.