圖片背景透明+翻轉(zhuǎn)

  • (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
    UIView *containerView = [transitionContext containerView];
    UIViewController *fromController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *toView = toController.view;
    // Enter
    if (toController.isBeingPresented) {
    _isEnter = YES;
    self.isTransitioning = YES;
    if ([self enter_configAnimateImageView]) {
    containerView.backgroundColor = [UIColor clearColor];
    [containerView addSubview:toView];
    [containerView addSubview:self.animateImageView];
    toView.alpha = 0;
    [self.imageBrowser setConnentHidden:YES];
    self.animateImageView.frame = CGRectMake(0, 0, 50, 50);
    self.animateImageView.center = containerView.center;
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
    toView.alpha = 1;
    self.animateImageView.frame = [self enterInFrame];
    } completion:^(BOOL finished) {
    [self completeTransition:transitionContext isEnter:YES];
    [self.animateImageView removeFromSuperview];
    }];
    } else {
    [containerView addSubview:toView];
    [self completeTransition:transitionContext isEnter:YES];
    }
    }

    // Out
    if (fromController.isBeingDismissed) {
    _isEnter = NO;
    self.isTransitioning = YES;
    UIView *fromAnimateView = [self.imageBrowser animatedView];
    CGRect toFrame = fromAnimateView.frame;
    if (fromAnimateView) {
    CGRect fromFrame = [fromAnimateView convertRect:fromAnimateView.frame toView:fromController.view];
    if (CGRectGetMidY(fromFrame) > fromController.view.center.y) {
    // 下移
    toFrame.origin.y = CGRectGetMaxY(fromController.view.frame);
    } else if (CGRectGetMidY(fromFrame) < fromController.view.center.y) {
    toFrame.origin.y = -CGRectGetHeight(fromFrame);
    } else {
    //漸變
    toFrame = CGRectZero;
    }
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
    if (CGRectEqualToRect(toFrame, CGRectZero)) {
    fromController.view.alpha = 0;
    } else {
    fromAnimateView.frame = toFrame;
    }
    fromController.view.backgroundColor = [fromController.view.backgroundColor colorWithAlphaComponent:0];

          } completion:^(BOOL finished) {
              [self completeTransition:transitionContext isEnter:NO];
          }];
      } else {
          [self completeTransition:transitionContext isEnter:NO];
      }
    

    }
    }

  • (void)completeTransition:(nullable id <UIViewControllerContextTransitioning>)transitionContext isEnter:(BOOL)isEnter {
    [transitionContext completeTransition:!transitionContext.transitionWasCancelled];
    self.isTransitioning = NO;
    if (isEnter) {
    [self.imageBrowser setConnentHidden:NO];
    }
    }

pragma mark - private

  • (BOOL)enter_configAnimateImageView {
    WKTopicBrowserModel *model= self.imageBrowser.currentModel;
    if (!model) return NO;

    CGSize imagesize;

    FLAnimatedImage *image = [[FLAnimatedImage alloc] initWithAnimatedGIFData:model.posterImageData];
    if (image) {
    self.animateImageView.animatedImage = image;
    imagesize = image.size;
    } else {
    self.animateImageView.image = [UIImage imageWithData:model.posterImageData];
    imagesize = self.animateImageView.image.size;
    }
    self.animateImageView.frame = CGRectZero;

    return YES;
    }

  • (CGRect)enterInFrame {
    CGSize imagesize;
    if (self.animateImageView.animatedImage) {
    imagesize = self.animateImageView.animatedImage.size;
    } else {
    imagesize = self.animateImageView.image.size;
    }
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    CGFloat maxScale = MIN(screenSize.width/imagesize.width, screenSize.height/imagesize.height);

      imagesize.width = imagesize.width * maxScale;
      imagesize.height = imagesize.height * maxScale;
    

    return CGRectMake((screenSize.width-imagesize.width)/2, (screenSize.height-imagesize.height)/2, imagesize.width, imagesize.height);
    }

pragma mark - getter

  • (FLAnimatedImageView *)animateImageView {
    if (!_animateImageView) {
    _animateImageView = [FLAnimatedImageView new];
    _animateImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _animateImageView;
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末叫榕,一起剝皮案震驚了整個(gè)濱河市怖辆,隨后出現(xiàn)的幾起案子散址,更是在濱河造成了極大的恐慌充石,老刑警劉巖谓形,帶你破解...
    沈念sama閱讀 216,470評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異烁兰,居然都是意外死亡脚囊,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,393評論 3 392
  • 文/潘曉璐 我一進(jìn)店門芦拿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來士飒,“玉大人查邢,你說我怎么就攤上這事〗湍唬” “怎么了扰藕?”我有些...
    開封第一講書人閱讀 162,577評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長芳撒。 經(jīng)常有香客問我实胸,道長,這世上最難降的妖魔是什么番官? 我笑而不...
    開封第一講書人閱讀 58,176評論 1 292
  • 正文 為了忘掉前任庐完,我火速辦了婚禮,結(jié)果婚禮上徘熔,老公的妹妹穿的比我還像新娘门躯。我一直安慰自己,他們只是感情好酷师,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,189評論 6 388
  • 文/花漫 我一把揭開白布讶凉。 她就那樣靜靜地躺著,像睡著了一般山孔。 火紅的嫁衣襯著肌膚如雪懂讯。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,155評論 1 299
  • 那天台颠,我揣著相機(jī)與錄音褐望,去河邊找鬼。 笑死串前,一個(gè)胖子當(dāng)著我的面吹牛瘫里,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播荡碾,決...
    沈念sama閱讀 40,041評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼谨读,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了坛吁?” 一聲冷哼從身側(cè)響起劳殖,我...
    開封第一講書人閱讀 38,903評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎拨脉,沒想到半個(gè)月后哆姻,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,319評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡女坑,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,539評論 2 332
  • 正文 我和宋清朗相戀三年填具,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了统舀。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片匆骗。...
    茶點(diǎn)故事閱讀 39,703評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡劳景,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出碉就,到底是詐尸還是另有隱情盟广,我是刑警寧澤,帶...
    沈念sama閱讀 35,417評論 5 343
  • 正文 年R本政府宣布瓮钥,位于F島的核電站筋量,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏碉熄。R本人自食惡果不足惜桨武,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,013評論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望锈津。 院中可真熱鬧呀酸,春花似錦、人聲如沸琼梆。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,664評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽茎杂。三九已至错览,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間煌往,已是汗流浹背倾哺。 一陣腳步聲響...
    開封第一講書人閱讀 32,818評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留刽脖,地道東北人悼粮。 一個(gè)月前我還...
    沈念sama閱讀 47,711評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像曾棕,于是被迫代替她去往敵國和親扣猫。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,601評論 2 353

推薦閱讀更多精彩內(nèi)容