iPhone SDK开发:禁止UIWebView的bounces
软件中如果需要添加HTML广告条,一个好的方法时内嵌一个UIWebView, 但是UIWebView默认是bounces enabled的, 查看各种资料,基本上有两种方法可以解决该问题
1. 在网页中重载页面的touch事件
2. 使用Private Frameworks
第一种很简单, 只需要在网页中实现就可以了, 没有被app store拒绝的风险,
修改网页的onload事件
1 2 3 | document.onload = function(){
document.ontouchmove = function(e){ e.preventDefault(); }
} |
第二种方法由于使用了Private Frameworks,所以APP能不能通过app store的审核就看运气了。 实际上也只是用了一个类定义, 也就是UIScroller的头文件
?Download UIScroller.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | #import <UIKit/UIView.h> @class UIScrollerIndicator; typedef struct { unsigned int :8; unsigned int :4; unsigned int :1; unsigned int :1; unsigned int :18; unsigned short _field1[8]; } CDAnonymousStruct8; @interface UIScroller : UIView { struct CGSize _contentSize; id _delegate; UIScrollerIndicator *_verticalScrollerIndicator; UIScrollerIndicator *_horizontalScrollerIndicator; struct { unsigned int bounceEnabled:1; unsigned int rubberBanding:1; unsigned int scrollingDisabled:1; unsigned int scrollingDisabledOnMouseDown:1; unsigned int directionalLockEnabled:1; unsigned int eventMode:3; unsigned int dragging:1; unsigned int mouseDragged:1; unsigned int scrollTriggered:1; unsigned int dontSelect:1; unsigned int contentHighlighted:1; unsigned int lockVertical:1; unsigned int lockHorizontal:1; unsigned int keepLocked:1; unsigned int bouncedVertical:1; unsigned int bouncedHorizontal:1; unsigned int mouseUpGuard:1; unsigned int pushedTrackingMode:1; unsigned int delegateScrollerDidScroll:1; unsigned int delegateScrollerAdjustSmoothScrollEndVelocity:1; unsigned int delegateScrollerShouldAdjustSmoothScrollEndForVelocity:1; unsigned int offsetIgnoresContentSize:1; unsigned int usingThumb:1; unsigned int thumbDetectionEnabled:1; unsigned int showScrollerIndicators:1; unsigned int indicatorSubrect:1; unsigned int indicatorHideInGesture:1; unsigned int pinIndicatorToContent:1; unsigned int indicatorStyle:2; unsigned int multipleDrag:1; unsigned int showBackgroundShadow:1; unsigned int cancelNextContentMouseUp:1; unsigned int displayingScrollIndicators:1; unsigned int dontResetStartTouchPosition:1; unsigned int verticalIndicatorShrunk:1; unsigned int horizontalIndicatorShrunk:1; unsigned int highlightContentImmediately:1; unsigned int adjustedEndOffset:1; unsigned int ignoreNextMouseDrag:1; unsigned int contentFitDisableScrolling:1; unsigned int reserved:21; } _scrollerFlags; float _scrollHysteresis; float _scrollDecelerationFactor; double _scrollToPointAnimationDuration; float _directionalScrollingAngle; float _farthestDistance; float _leftRubberBandWidth; float _rightRubberBandWidth; float _topRubberBandHeight; float _bottomRubberBandHeight; float _bottomBufferHeight; struct CGPoint _initialTouchPosition; struct CGPoint _startTouchPosition; double _startTouchTime; struct CGPoint _startOffset; struct CGPoint _lastTouchPosition; double _lastTouchTime; double _lastUpdateTime; struct CGPoint _lastUpdateOffset; UIView *_lastHighlightedView; CDAnonymousStruct8 _velocity; CDAnonymousStruct8 _previousVelocity; CDAnonymousStruct8 _decelerationFactor; CDAnonymousStruct8 _decelerationLnFactor; struct CGPoint _stopOffset; struct __GSHeartbeat *_scrollHeartbeat; struct CGRect _indicatorSubrect; UIView *_scrollerShadows; UIView *_contentShadows; id _scrollNotificationViews; struct CGSize _gridSize; CDAnonymousStruct8 _gridBounceLnFactor; } - (id)initWithFrame:(struct CGRect)fp8; - (void)dealloc; - (void)setFrame:(struct CGRect)fp8; - (void)setContentSize:(struct CGSize)fp8; - (struct CGSize)contentSize; - (void)setAdjustForContentSizeChange:(BOOL)fp8; - (void)setOffset:(struct CGPoint)fp8; - (struct CGPoint)offset; - (void)setBottomBufferHeight:(float)fp8; - (float)bottomBufferHeight; - (void)scrollByDelta:(struct CGSize)fp8; - (void)scrollByDelta:(struct CGSize)fp8 animated:(BOOL)fp16; - (void)removeFromSuperview; - (void)_didMoveFromWindow:(id)fp8 toWindow:(id)fp12; - (struct CGPoint)_pinnedScrollPointForPoint:(struct CGPoint)fp8; - (void)scrollPointVisibleAtTopLeft:(struct CGPoint)fp8; - (void)_scrollAnimationEnded; - (void)scrollPointVisibleAtTopLeft:(struct CGPoint)fp8 animated:(BOOL)fp16; - (void)scrollRectToVisible:(struct CGRect)fp8 animated:(BOOL)fp24; - (void)scrollRectToVisible:(struct CGRect)fp8; - (void)setScrollToPointAnimationDuration:(double)fp8; - (double)scrollToPointAnimationDuration; - (void)setScrollHysteresis:(float)fp8; - (void)setEventMode:(int)fp8; - (void)setAllowsRubberBanding:(BOOL)fp8; - (void)setAllowsFourWayRubberBanding:(BOOL)fp8; - (void)setDirectionalScrolling:(BOOL)fp8; - (void)setDirectionalScrollingAngle:(float)fp8; - (void)setScrollingEnabled:(BOOL)fp8; - (void)setScrollDecelerationFactor:(float)fp8; - (void)setBounces:(BOOL)fp8; - (void)setGridSize:(struct CGSize)fp8; - (void)setThumbDetectionEnabled:(BOOL)fp8; - (void)setShowScrollerIndicators:(BOOL)fp8; - (void)setScrollerIndicatorSubrect:(struct CGRect)fp8; - (void)setScrollerIndicatorsPinToContent:(BOOL)fp8; - (void)setScrollerIndicatorStyle:(int)fp8; - (void)_hideScrollIndicators; - (void)displayScrollerIndicators; - (void)setRubberBand:(float)fp8 forEdges:(int)fp12; - (BOOL)releaseRubberBandIfNecessary; - (void)setDelegate:(id)fp8; - (id)delegate; - (void)setShowBackgroundShadow:(BOOL)fp8; - (id)hitTest:(struct CGPoint)fp8 forEvent:(struct __GSEvent *)fp16; - (void)mouseDown:(struct __GSEvent *)fp8; - (void)setOffsetForDragOffset:(struct CGPoint)fp8 withEvent:(struct __GSEvent *)fp16 duration:(float)fp20; - (struct CGPoint)dragStartOffset; - (void)mouseDragged:(struct __GSEvent *)fp8; - (void)gestureStarted:(struct __GSEvent *)fp8; - (void)gestureChanged:(struct __GSEvent *)fp8; - (void)gestureEnded:(struct __GSEvent *)fp8; - (void)_popTrackingRunLoopMode; - (void)mouseUp:(struct __GSEvent *)fp8; - (BOOL)canHandleSwipes; - (int)swipe:(int)fp8 withEvent:(struct __GSEvent *)fp12; - (BOOL)cancelMouseTracking; - (void)cancelNextContentMouseUp; - (void)contentMouseUpInView:(id)fp8 withEvent:(struct __GSEvent *)fp12; - (void)highlightView:(id)fp8 state:(BOOL)fp12; - (void)setHighlightContentImmediately:(BOOL)fp8; - (CDAnonymousStruct8)velocity; - (BOOL)isScrolling; - (BOOL)isDecelerating; - (BOOL)adjustSmoothScrollEnd:(CDAnonymousStruct8)fp8; @end |
还有UIScroller用到的UIScrollerIndicator类的定义
?Download UIScrollerIndicator.h
1 2 3 4 5 6 7 8 9 10 11 | #import <UIKit/UIView.h> @interface UIScrollerIndicator : UIView { int _style; } - (id)initInScroller:(id)fp8 style:(int)fp12; - (void)drawRect:(struct CGRect)fp8; @end |
然后给UIWeb添加一个extension
1 2 3 | @interface UIWebView(DisableBounces) -(void) DisableBounces; @end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | @implementation UIWebView(DisableBounces) - (void) DisableBounces { for( UIView* view in self.subviews ) { if( [view isKindOfClass:[UIScroller class]] ) { [(UIScroller*)view setBounces:NO]; [(UIScroller*)view setScrollingEnabled:NO]; } } } @end |
最后需要在frameworks中添加 WebCore 、 WebKit两个frameworks
第二种方法的好处是,可以针对任何网页, 但是是否能通过app store的审核还有待验证。
转载自:FLYBLOG [http://www.flyblog.info]
本文链接地址:http://www.flyblog.info/catprogramming/303.html
相关文章
说真的…什么时候教我python ?
[...] 上的 licufa软件草稿设计软件Balsamiq Mockups 上的 coollelaiPhone SDK开发:禁止UIWebView的bounces 上的 小桥流水人家热播连续剧《我的团长我的团》 上的 [...]