以前工作很忙,趕進度, 遇到一些需要的功能的話,就是簡單的上網找,找到后看懂代碼后,修修改改就用到項目中了。現在每天還是很忙,但還是特細抽出點時間把,學習點基礎知識, 把第三方的逐漸替換掉。
1、 先說拉伸放大的實現原理
scrollview的屬性介紹:
contentSize是scrollview可以滾動的區域,比如frame = (0 ,0 ,320 ,480) contentSize = (320 ,960),代表你的scrollview可以上下滾動,滾動區域為frame大小的兩倍。contentOffset是scrollview當前顯示區域頂點相對于frame頂點的偏移量,比如上個例子你拉到最下面,contentoffset就是(0 ,480),也就是y偏移了480contentInset是scrollview的contentview的頂點相對于scrollview的位置,例如你的contentInset = (0 ,100),那么你的contentview就是從scrollview的(0 ,100)開始顯示.
-
首相自定義一個adjustView, 把adjustView添加到scrollview, 要減弱adjustView 和scrollview 的正常內容的影響, 那么adjustView的Y值就不可能從0開始, 只能從-h(h建設為view1的高度)。
- (void)reSizeView{ //重置adjustView位置 [adjustView setFrame:CGRectMake(0, -1*h, CGRectGetWidth(adjustView.frame), h)]; }
但這樣運行會造成如下情況:
開始運行的時候看不到adjustView,向下拉的時候才會出現,這時候就需要設置一下, scrollview的contentInset屬性就好了(屬性介紹看上面)。
_scrollView.contentInset = UIEdgeInsetsMake(h, 0, 0, 0);
這樣運行起來,就可以看到scrollview上面的自定義adjustView;但是向下拉時,怎么讓圖片變大呢?
** 其實實現拉伸放大效果的最關鍵點是:UIImageView的contentMode屬性(UIViewContentModeScaleAspectFill),正式因為這個屬性,調整adjustView的大小的話,就可以改變圖片的大小 **
img.contentMode= UIViewContentModeScaleAspectFill;
img.clipsToBounds = YES;
所以可以通過監聽scrollview 的滾動事件, 來改變adjustView的frame
scrollview的代理方法:
- (void)scrollViewDidScroll:(UIScrollView)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y;
if(offsetY < h * -1) {
CGRect currentFrame = _expandView.frame;
currentFrame.origin.y = offsetY;
currentFrame.size.height = -1offsetY;
img.frame = currentFrame;
} }
說明:img可是是上文說的adjustView,或者是adjustView的子控件。
當然,如果你的自定義控件里面還要放label、button之類的話如下:
autoresizingMask屬性,自動調整子控件和父控件的位置、大小。 通過控制這個屬性可以達到你要的效果。這個屬性的語義:
http://www.cnblogs.com/jiangyazhou/archive/2012/06/26/2563041.html
2、 改變導航欄文字的顏色
如下:改變title的文字顏色和返回按鈕的顏色 , 要自己計算在代理里面的調用時機。
// [self.navigationController.navigationBar lt_setBackgroundColor: [color colorWithAlphaComponent:alpha]];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:17], NSFontAttributeName, nil]];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];