我正在创建一个评论部分,就像Facebook在iOS应用程序中使用它的消息部分一样.我希望UITextView调整高度,以便我输入的文本适合它,而不是你必须滚动才能看到溢出的文本.我有什么想法可以这样做吗?我调查了可能使用的CGRect是分配给文本视图的大小和高度,然后匹配内容大小:
CGRect textFrame = textView.frame;
textFrame.size.height = textView.contentSize.height;
textView.frame = textFrame;
Run Code Online (Sandbox Code Playgroud)
我假设我需要某种功能来检测文本何时到达边界UITextView然后调整视图的高度?有没有人在用同样的概念挣扎?
我环顾四周,我不能为我的生活找到一种方法来替换backbarbuttonitem滑动手势.我想向左滑动,让应用程序恢复到以前的视图控制器.只是为了澄清我正在使用a UINavigationController管理我的所有View控制器.有任何想法吗?或者这不可能吗?谢谢!
uinavigationcontroller uiswipegesturerecognizer backbarbuttonitem
我制作了一个UIImage Objective C类别来容纳这个功能:
#import "UIImage+fixOrientation.h"
@implementation UIImage (fixOrientation)
- (UIImage *)fixOrientation
{
// No-op if the orientation is already correct
if (self.imageOrientation == UIImageOrientationUp) return self;
// We need to calculate the proper transformation to make the image upright.
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
CGAffineTransform transform = CGAffineTransformIdentity;
switch (self.imageOrientation) {
case UIImageOrientationDown:
case UIImageOrientationDownMirrored:
transform = CGAffineTransformTranslate(transform, self.size.width, self.size.height);
transform = CGAffineTransformRotate(transform, M_PI);
break;
case UIImageOrientationLeft:
case UIImageOrientationLeftMirrored:
transform …Run Code Online (Sandbox Code Playgroud)