iPhone SDK开发:禁止UIWebView的bounces

nerosoft 2009-03-11 02:55:31


软件中如果需要添加HTML广告条,一个好的方法时内嵌一个UIWebView, 但是UIWebView默认是bounces enabled的, 查看各种资料,基本上有两种方法可以解决该问题
1. 在网页中重载页面的touch事件
2. 使用Private Frameworks

第一种很简单, 只需要在网页中实现就可以了, 没有被app store拒绝的风险,
修改网页的onload事件

document.onload = function(){
document.ontouchmove = function(e){ e.preventDefault(); }
}

第二种方法由于使用了Private Frameworks,所以APP能不能通过app store的审核就看运气了。 实际上也只是用了一个类定义, 也就是UIScroller的头文件

#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类的定义

#import <UIKit/UIView.h>

@interface UIScrollerIndicator : UIView
{
int _style;
}

- (id)initInScroller:(id)fp8 style:(int)fp12;
- (void)drawRect:(struct CGRect)fp8;

@end

然后给UIWeb添加一个extension
?View Code OBJC

1
2
3



@interface UIWebView(DisableBounces)
-(void) DisableBounces;
@end


@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的审核还有待验证。



原文 http://www.flyblog.info/catprogramming/303.html
...全文
773 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
aizhuhui 2009-03-14
  • 打赏
  • 举报
回复
nero前輩, 小僧說難聽點.. 這裡就像是"xx糊不上牆", 您還是有時間一起來幫小僧整整wiki吧

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧