最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS實現(xiàn)頭部拉伸效果

 更新時間:2018年05月08日 14:35:27   作者:u010596262  
這篇文章主要為大家詳細(xì)介紹了iOS實現(xiàn)頭部拉伸效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了iOS實現(xiàn)頭部拉伸效果展示的具體代碼,供大家參考,具體內(nèi)容如下

主要涉及到導(dǎo)航欄透明度、圖片拉伸、列表頭部等。

  • 導(dǎo)航欄透明度的實現(xiàn)。
  • 列表拖動距離的監(jiān)聽,及圖片放大的實現(xiàn)。

導(dǎo)航透明度的設(shè)置

添加系統(tǒng)導(dǎo)航欄的Category實現(xiàn)

聲明部分:

@interface UINavigationBar (BackgroundColor)
- (void)lt_setBackgroundColor:(UIColor *)color;
@end

實現(xiàn)部分:

#import <objc/runtime.h>

@implementation UINavigationBar (BackgroundColor)
static char overlayKey;

- (UIView *)overlay
{
  return objc_getAssociatedObject(self, &overlayKey);
}

- (void)setOverlay:(UIView *)overlay
{
  objc_setAssociatedObject(self, &overlayKey, overlay, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)lt_setBackgroundColor:(UIColor *)color
{
  if (!self.overlay) {
    [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    // insert an overlay into the view hierarchy
    self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -20, [UIScreen mainScreen].bounds.size.width, self.bounds.size.height + 20)];
    self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    [self insertSubview:self.overlay atIndex:0];
  }
  self.overlay.backgroundColor = color;
}

@end

監(jiān)聽列表拖動及實現(xiàn)圖片放大

主要是監(jiān)聽滾動的距離(scrollViewDidScroll:方法)

#import "StretchViewController.h"
#import "UINavigationBar+BackgroundColor.h"

// 背景圖片的寬高比例
#define ratio 0.8

@interface StretchViewController () <UITableViewDelegate, UITableViewDataSource>

// 可放大的背景圖片
@property (nonatomic, strong) UIImageView *bgView;
// 記錄原始大小
@property (assign) CGRect originalFrame;

@property (nonatomic, strong) UITableView *tableView;
@end

@implementation StretchViewController

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  //[self.navigationController setNavigationBarHidden:YES animated:animated];

  //self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  //self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
  //self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
  // 設(shè)置導(dǎo)航欄底部分割線為透明
  [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}

- (void)viewDidLoad {
  [super viewDidLoad];
  // 設(shè)置全透明
  [self.navigationController.navigationBar lt_setBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0]];

  // Do any additional setup after loading the view.
  self.view.backgroundColor = [UIColor lightGrayColor];

  self.bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width*ratio)];
  self.bgView.image = [UIImage imageNamed:@"bg-mine"];
  self.originalFrame = self.bgView.frame;
  [self.view addSubview:self.bgView];

  self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height-64) style:UITableViewStylePlain];
  self.tableView.backgroundColor = [UIColor clearColor];
  self.tableView.showsVerticalScrollIndicator = NO;
  self.tableView.delegate = self;
  self.tableView.dataSource = self;

  // 1. contentInset
  //table.contentInset = UIEdgeInsetsMake(160, 0, 0, 0);

  // 2. heatView
  UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 160)];
  headView.backgroundColor = [UIColor clearColor];
  self.tableView.tableHeaderView = headView;
  [self.view addSubview:self.tableView];
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];
  if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellIdentifier"];
  }
  cell.textLabel.text = @"測試數(shù)據(jù)";
  return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return 10;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{

  CGFloat yOffset = scrollView.contentOffset.y; // 向上滑動,offset是增加的;向下滑動,是減少的
  if (yOffset < 160) { // 當(dāng)滑動到導(dǎo)航欄底部時
    CGFloat colorAlpha = yOffset/160;

//    self.navigationController.navigationBar.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:colorAlpha];
    [self.navigationController.navigationBar lt_setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:colorAlpha]];

  } else { // 超過導(dǎo)航欄底部了
    [self.navigationController.navigationBar lt_setBackgroundColor:[UIColor whiteColor]];
  }

  // 往上滑動效果、處理放大效果
  if (yOffset > 0) {
    self.bgView.frame = ({
      CGRect frame = self.bgView.frame;
      frame.origin.y = self.originalFrame.origin.y - yOffset;
      frame;
    });
  } else { // 往下移動,放大效果
    self.bgView.frame = ({
      CGRect frame = self.originalFrame;
      frame.size.height = self.originalFrame.size.height - yOffset;
      frame.size.width = frame.size.height/ratio;

      //
      frame.origin.x = self.originalFrame.origin.x - (frame.size.width - self.originalFrame.size.width)/2;
      frame;
    });
  }

}
@end

以上是對系統(tǒng)原生的導(dǎo)航欄進(jìn)行透明度設(shè)置。

也可進(jìn)行自定義視圖設(shè)置為導(dǎo)航欄

效果如下:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

  • iOS實現(xiàn)圖片存在本地、再從本地獲取圖片的功能

    iOS實現(xiàn)圖片存在本地、再從本地獲取圖片的功能

    本文主要介紹了iOS實現(xiàn)圖片存在本地、再從本地獲取圖片的功能的代碼。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • 詳解IOS UITableViewCell 的 imageView大小更改

    詳解IOS UITableViewCell 的 imageView大小更改

    這篇文章主要介紹了詳解IOS UITableViewCell 的 imageView大小更改的相關(guān)資料,需要的朋友可以參考下
    2017-07-07
  • IOS中對Url進(jìn)行編碼和解碼示例

    IOS中對Url進(jìn)行編碼和解碼示例

    本篇文章主要介紹了IOS中對Url進(jìn)行編碼和解碼示例,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-11-11
  • iOS中如何使用iconfont圖標(biāo)實例詳解

    iOS中如何使用iconfont圖標(biāo)實例詳解

    iconfont大家在開發(fā)中應(yīng)該會經(jīng)常用到,下面這篇文章主要給大家介紹了在iOS中如何使用iconfont圖標(biāo)實例的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • iOS抽屜效果開發(fā)案例分享

    iOS抽屜效果開發(fā)案例分享

    這篇文章主要為大家分享了iOS抽屜效果開發(fā)案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-04-04
  • IOS 百度糯米客戶端登錄BUG

    IOS 百度糯米客戶端登錄BUG

    這篇文章主要介紹了IOS 百度糯米客戶端登錄BUG,問題分析及解決方案,本文介紹的非常詳細(xì),具有參考價值,特此分享供大家學(xué)習(xí)
    2016-01-01
  • iOS實現(xiàn)圓環(huán)比例圖

    iOS實現(xiàn)圓環(huán)比例圖

    這篇文章主要為大家詳細(xì)介紹了iOS實現(xiàn)圓環(huán)比例圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • iOS在頁面銷毀時如何優(yōu)雅的cancel網(wǎng)絡(luò)請求詳解

    iOS在頁面銷毀時如何優(yōu)雅的cancel網(wǎng)絡(luò)請求詳解

    這篇文章主要給大家介紹了關(guān)于iOS在頁面銷毀時如何優(yōu)雅的cancel網(wǎng)絡(luò)請求的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • 最新評論

    新沂市| 西乌| 通江县| 应城市| 佳木斯市| 旬阳县| 秀山| 泸西县| 枣强县| 汤阴县| 汉阴县| 雅安市| 无棣县| 彭山县| 海阳市| 桃园市| 柘荣县| 文山县| 固原市| 浦北县| 崇左市| 吴旗县| 泾源县| 舞阳县| 雷波县| 四会市| 湘阴县| 景谷| 苍溪县| 天峻县| 闵行区| 罗甸县| 郧西县| 将乐县| 建昌县| 沭阳县| 嘉善县| 铜陵市| 虞城县| 始兴县| 万盛区|