簡體   English   中英

旋轉M_PI_4后,iOS UIImageView消失

[英]iOS UIImageView disappears after rotation M_PI_4

這里基本上發生的是我正在向UIBarButtonItem添加一個自定義視圖,我需要將其旋轉45度,如果旋轉90度或180度旋轉效果很好,但是當它小於90度時,對象會變形,並且在45deg上,對象消失了。 以下是按鈕和動畫的片段。

UIImageView * menuImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plus.png"]];
menuButton = [[UIBarButtonItem alloc] initWithCustomView:menuImage];
UITapGestureRecognizer * tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleMenuView:)];
[menuImage addGestureRecognizer:tap1];
[menuImage setUserInteractionEnabled:YES];
[menuImage.layer setShadowColor:[UIColor blackColor].CGColor];
[menuImage.layer setShadowOffset:CGSizeMake(ShadowSizeWidth, ShadowSizeHeight)];
[menuImage.layer setShadowOpacity:ShadowOpacity];
[menuImage.layer setShadowRadius:ShadowRadius];

[self.navigationItem setRightBarButtonItem:menuButton];

輪換:

[UIView animateWithDuration:animationRotateButtonDuration delay:0.0f options:UIViewAnimationCurveLinear animations:^{
    CGAffineTransform myTransform = CGAffineTransformMakeRotation(-M_PI_4);

    UIBarButtonItem * currentItem =  menuButton;

    currentItem.customView.transform = myTransform;

}completion:^(BOOL finished){
}];

使用anchorPoint並導入"QuartzCore/QuartzCore.h"

currentItem.customView.layer.anchorPoint = CGPointMake(1.0, 0.0);//it is not fixed point you have to change.

我認為這對你有所幫助。

我和你有完全相同的問題。 我的問題是我在viewDidLoad中進行旋轉。

嘗試在viewDidAppear中執行它,它對我有用

如果UIImageView contentMode設置為UIViewContentModeScaleAspectFit或其他縮放方面,則旋轉將導致圖像消失。

將contentMode更改為UIViewContentModeCenter應該可以解決問題。

是的,我有同樣的問題。 我在viewDidLayoutSubViews中執行了一次調度...... CGAffineTransformMakeRotation(M_PI_2)是奇怪的。 和CGAffineTransformMakeRotation(M_PI); 有效,但不是這個。 如果有人知道這是否是一個報道的問題我會喜歡這個鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM