父類UIView方法
# autoresizingMask - 現在基本棄用,改用autoLayout
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
# transform - 形變屬性【結構體 - 不能直接賦值】
CGAffineTransformMakeRotation(CGFloat angle);
CGAffineTransformMakeScale(CGFloat sx, CGFloat sy);
CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty);
CGAffineTransformRotation(CGAffineTransform t, CGFloat angle);
CGAffineTransformScale(CGAffineTransform t, CGFloat sx, CGFloat sy);
CGAffineTransformTranslation(CGAffineTransform t, CGFloat tx, CGFloat ty);
複製程式碼
UIScrollView中容易混淆的屬性
- contentSize 內容尺寸
- contentInset 內容邊框尺寸
- contentOffset 可視框偏移
UIScrollViewDelegate代理方法
# 滾動時會呼叫,任何方式觸發contentOffset變化都會呼叫,呼叫頻率高
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
# 開始拖拽時呼叫
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
# 停止拖拽時呼叫
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView withDecelerate:(BOOL)decelarate;
# 即將停止滾動時呼叫(拖拽鬆開後開始減速時呼叫)
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
# 滾動停止時呼叫,特殊情況:當一次減速動畫尚未結束的時候再次拖拽,didEndDecelerating不會被呼叫
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
# 開始縮放時呼叫
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view;
# 停止縮放時呼叫
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale;
# 正在縮放時呼叫
- (void)scrollViewDidZoom:(UIScrollView *)scrollView;
複製程式碼
UIScrollView基本用法
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor = [UIColor redColor];
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(320, 460*10);
scrollView.contentInset = UIEdgeInsetsMake(0, 50, 50, 0);
# 這裡好奇怪,number用任何數字代替,整個code就不會程式碼高亮了,估計是markdown的一個缺陷
scrollView.contentOffset = CGPointMake( number , number);
scrollView.bounces = NO;
scrollView.pagingEnabled = YES;
scrollView.scrollEnabled = NO;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 50, 0, 0);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.maximumZoomScale = 2.0;
scrollView.minimumZoomScale = 0.5;
scrollView.directionalLockEnabled = YES;
[self.view addSubview:scrollView];
複製程式碼