PagingEnabled只能翻過(guò)整頁(yè),下面幾個(gè)簡(jiǎn)單的設(shè)置即可實(shí)現(xiàn)
創(chuàng)新互聯(lián)自成立以來(lái),一直致力于為企業(yè)提供從網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè)、電子商務(wù)、網(wǎng)站推廣、網(wǎng)站優(yōu)化到為企業(yè)提供個(gè)性化軟件開(kāi)發(fā)等基于互聯(lián)網(wǎng)的全面整合營(yíng)銷服務(wù)。公司擁有豐富的網(wǎng)站建設(shè)和互聯(lián)網(wǎng)應(yīng)用系統(tǒng)開(kāi)發(fā)管理經(jīng)驗(yàn)、成熟的應(yīng)用系統(tǒng)解決方案、優(yōu)秀的網(wǎng)站開(kāi)發(fā)工程師團(tuán)隊(duì)及專業(yè)的網(wǎng)站設(shè)計(jì)師團(tuán)隊(duì)。技術(shù)點(diǎn):
1. 創(chuàng)建一個(gè)繼承UIView的視圖,并設(shè)置clipsToBounds= YES
2. 添加一個(gè)UIscrollView控件,將其寬度設(shè)置為自定義翻頁(yè)的寬度
3. 設(shè)置UIScrollview 的clipsToBounds= NO
4. 確保本View的寬度大于UIScrollView的寬度用于顯示預(yù)覽內(nèi)容
5. 重寫(xiě)本View的hittest方法,為了確保用戶滑動(dòng)UIscrollview以外的空間時(shí)也可以觸發(fā)UIscrollview滑動(dòng)
ok! 下面是代碼,為了方便,使用圖片作為顯示的每一頁(yè)
#define kLJItemWidth 240
@implementation MyScrollview {
UIScrollView *scrollview;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
scrollview = ({
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(40, 0, kLJItemWidth, frame.size.height)];
scroll.pagingEnabled = YES;
scroll.clipsToBounds = NO;
scroll;
}) ;
[self addSubview:scrollview];
self.clipsToBounds = YES;
}
return self;
}
-(void)loadImages:(NSArray *)array{
int index = 0;
[scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
for(NSString * name in array){
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:name]];
iv.contentMode = UIViewContentModeScaleToFill;
CGRect fra = iv.frame;
fra.size.width = kLJItemWidth;
fra.origin.x = index * kLJItemWidth;
iv.frame = fra;
[scrollview addSubview:iv];
index++;
}
scrollview.contentSize = CGSizeMake(scrollview.frame.size.width*index, scrollview.frame.size.height);
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *view = [super hitTest:point withEvent:event];
if ([view isEqual:self])
{
for (UIView *subview in scrollview.subviews)
{
CGPoint offset = CGPointMake(point.x - scrollview.frame.origin.x + scrollview.contentOffset.x - subview.frame.origin.x,
point.y - scrollview.frame.origin.y + scrollview.contentOffset.y - subview.frame.origin.y);
if ((view = [subview hitTest:offset withEvent:event]))
{
return view;
}
}
return scrollview;
}
return view;
}
@end
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。