真的很奇怪的一个被卡住但奇怪的是我.
你有一个imageView包含图像.你缩小尺寸,imageView然后告诉它使用UIViewContentModeScaleAspectFit.所以你imageView可能是300乘200但你的缩放图像可能是300乘118或228乘200因为它aspectfit.
你到底如何得到实际图像的大小?
imageView.image.size是原始图像的大小.
imageview.frame是imageview不包含图像的框架.
imageview.contentstretch也不起作用
我有以下代码:
UITapGestureRecognizer *showStoryTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showNewsStory:)];
[showStoryTapRecognizer setDelegate:self];
[self.storyImageView_ addGestureRecognizer:showStoryTapRecognizer];
[showStoryTapRecognizer release];
Run Code Online (Sandbox Code Playgroud)
然而这并没有触发showNewsStory,为什么会这样呢?我在图像视图中启用了userInteraction.
我有我的UIImageView,我把一个图像放入其中,我调整大小如下:
UIImageView *attachmentImageNew = [[UIImageView alloc] initWithFrame:CGRectMake(5.5, 6.5, 245, 134)];
attachmentImageNew.image = actualImage;
attachmentImageNew.backgroundColor = [UIColor redColor];
attachmentImageNew.contentMode = UIViewContentModeScaleAspectFit;
Run Code Online (Sandbox Code Playgroud)
我尝试UIImageView通过这样做获得调整大小的图片的宽度:
NSLog(@"Size of pic is %f", attachmentImageNew.image.size.width);
Run Code Online (Sandbox Code Playgroud)
但它实际上返回原始图片的宽度.关于如何获得我在屏幕上看到的图片框架的任何想法?
编辑:这是我的UIImageView外观,红色区域是它的backgroundColor

我期待在更换ALAssetsLibrary与Photos框架在我的应用程序.
我可以很好地检索照片,集合和资源(甚至可以将它们写回来),但是看不到任何地方可以访问照片的元数据({Exif},{TIFF},{GPS}等字典,等等...).
ALAssetsLibrary有办法.UIImagePickerController有办法.Photos也必须有办法.
我看到它PHAsset有一个location属性可以用于GPS词典,但我希望访问所有的元数据,包括面部,方向,曝光,ISO和吨更多.
目前苹果处于测试阶段2.也许还有更多的API需要推出?
UPDATE
没有官方的方法只使用Photos API来做到这一点.
但是,您可以在下载图像数据后读取元数据.有几个方法来做到这一点使用两种PHImageManager或PHContentEditingInput.
该PHContentEditingInput方法需要较少的代码,不需要您导入ImageIO.我把它包装在PHAsset类别中.
我想对UIImageView缩放,旋转进行2次操作,我有2个问题:
答:我为ex做了缩放操作.当我尝试进行旋转时,将
UIImageView其设置为初始大小,我想知道如何保持缩放UIImageView并从缩放图像进行旋转.B.我想将缩放操作与旋转相结合,我不知道如何实现这一点:
- (void)viewDidLoad
{
foo = [[UIImageView alloc]initWithFrame:CGRectMake(100.0, 100.0, 600, 800.0)];
foo.userInteractionEnabled = YES;
foo.multipleTouchEnabled = YES;
foo.image = [UIImage imageNamed:@"earth.jpg"];
foo.contentMode = UIViewContentModeScaleAspectFit;
foo.clipsToBounds = YES;
[self.view addSubview:foo];
}
//---pinch gesture---
UIPinchGestureRecognizer *pinchGesture =
[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
[foo addGestureRecognizer:pinchGesture];
[pinchGesture release];
//---rotate gesture---
UIRotationGestureRecognizer *rotateGesture =
[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotateGesture:)];
[foo addGestureRecognizer:rotateGesture];
[rotateGesture release];
//---handle pinch gesture---
-(IBAction) handlePinchGesture:(UIGestureRecognizer *) sender {
NSLog(@"Pinch");
CGFloat factor = [(UIPinchGestureRecognizer *) …Run Code Online (Sandbox Code Playgroud) 你如何才能有效地检测到a的非透明像素上的触摸UIImageView?
考虑下面的图像,显示为UIImageView.目标是仅在触摸发生在图像的非透明(在这种情况下为黑色)区域时使手势识别器响应.

hitTest:withEvent:或者pointInside:withEvent:,尽管这种方法可能非常低效,因为这些方法在触摸事件期间被多次调用.我有一个应用程序,我有一个UIImageView显示主图像和另一个UIImageView被用作掩码,显示一个透明的圆形和不透明的外面,这个圆圈可以使用a移动UIPanGestureRecognizer,我想知道一个方法来裁剪里面的图像将圆圈变成新的图像.这是附加的代码和屏幕截图
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// create pan gesture
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [[self makeCircleAtLocation:self.view.center radius:100.0] CGPath];
shapeLayer.strokeColor = [[UIColor clearColor] CGColor];
shapeLayer.fillColor = nil;
shapeLayer.lineWidth = 3.0;
// Add CAShapeLayer to our view
[self.view.layer addSublayer:shapeLayer];
// Save this shape layer in a class property for future reference,
// namely so we …Run Code Online (Sandbox Code Playgroud) UIImageView错误地渲染图像的大小.使用Scale Aspect Fit,如果UIImageView是正方形,则图像是正确的宽高比,在图像未填充的区域中具有透明度.
//Image is Square & Correct Size
var imageView = UIImageView(frame: CGRectMake(0, 50, 320, 320))
imageView.clipsToBounds = true
imageView.contentMode = UIViewContentMode.ScaleAspectFit
//Image is Rectangle & Incorrect Size
var imageView = UIImageView(frame: CGRectMake(0, 50, 320, 450))
imageView.clipsToBounds = true
imageView.contentMode = UIViewContentMode.ScaleAspectFit
Run Code Online (Sandbox Code Playgroud)
UIImageView需要触摸边缘并在屏幕的顶部和底部具有透明空间,并且内部图像需要保持其原始比率而不是拉伸更高.我附上了两张UIImageView内部图像渲染图像.

我正试图从相机实时显示UIImage,看来我的UIImageView没有正确显示图像.这是AVCaptureVideoDataOutputSampleBufferDelegate必须实现的方法
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
// Create a UIImage from the sample buffer data
UIImage *theImage = [self imageFromSampleBuffer:sampleBuffer];
// NSLog(@"Got an image! %f %f", theImage.size.width, theImage.size.height);
// NSLog(@"The image view is %@", imageView);
// UIImage *theImage = [[UIImage alloc] initWithData:[NSData
// dataWithContentsOfURL:[NSURL
// URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
[self.session stopRunning];
[imageView setImage: theImage];
}
Run Code Online (Sandbox Code Playgroud)
为了解决容易出错的问题:
setImage:theImage到imageView,则图像被正确加载(并且第二次调用NSLog报告非零对象).imageFromSampleBuffer:很好,因为NSLog报告的大小为360x480,这是我预期的大小.我正在使用的代码是最近发布的AVFoundation苹果公司提供片段在这里.
特别是,这是我用来设置AVCaptureSession对象和朋友的代码(我很少理解),并从Core Video缓冲区创建UIImage对象(这就是imageFromSampleBuffer方法).
最后,我可以让应用程序崩溃,如果我尝试发送drawInRect:到一个普通的UIView子类与UIImage …
我想在IB设计中加载样本图像,UIImageView在编辑界面时在Interface Builder中显示.以下代码不起作用,因为IB中的视图占位符保持为空(视图区域仅包含UIImageView文本):
@IBDesignable
class TestImageView : UIImageView
{
override func prepareForInterfaceBuilder() {
//let bundle = NSBundle.mainBundle()
let bundle = NSBundle(forClass: nil)
let imagePath = bundle.pathForResource("Test", ofType: "jpg")
self.image = UIImage(contentsOfFile: imagePath)
}
}
Run Code Online (Sandbox Code Playgroud)
注意:
UIImageViewIB中图像属性的图像显示).这是用Xcode 6 beta 3测试的.
更新:在这两种情况下,我获得的捆绑路径是"/Applications/Temporary/Xcode6-Beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Overlays".在该路径中,图像显然不存在.
uiimageview ×10
ios ×7
iphone ×7
objective-c ×3
swift ×2
avfoundation ×1
cocoa-touch ×1
hittest ×1
ios4 ×1
ios8 ×1
ipad ×1
pinch ×1
rotation ×1
uiimage ×1
zoom ×1