在我的应用程序中,我想向用户呈现一个全屏照片查看器,就像照片应用程序中使用的那样.这仅适用于单张照片,因此应该非常简单.我只是希望用户能够查看这张能够缩放和平移的照片.
我有大部分工作.而且,如果我不将UIImageView作为中心,那么一切都表现得非常完美.但是,当图像被充分缩小时,我真的希望UIImageView在屏幕上居中.我不希望它粘在滚动视图的左上角.
一旦我试图将这个视图居中,我的垂直可滚动区域似乎比它应该更大.因此,一旦我放大一点,我就能够滚动大约100像素超过图像的顶部.我究竟做错了什么?
@interface MyPhotoViewController : UIViewController <UIScrollViewDelegate>
{
UIImage* photo;
UIImageView *imageView;
}
- (id)initWithPhoto:(UIImage *)aPhoto;
@end
@implementation MyPhotoViewController
- (id)initWithPhoto:(UIImage *)aPhoto
{
if (self = [super init])
{
photo = [aPhoto retain];
// Some 3.0 SDK code here to ensure this view has a full-screen
// layout.
}
return self;
}
- (void)dealloc
{
[photo release];
[imageView release];
[super dealloc];
}
- (void)loadView
{
// Set the main view of this UIViewController to be a UIScrollView.
UIScrollView *scrollView …Run Code Online (Sandbox Code Playgroud) 伙计们,我想在添加到UIImageVIew之后点击我的uiButton,但它不起作用.这是我的代码:
UIButton *btnDetail = [[UIButton buttonWithType:UIButtonTypeDetailDisclosure]retain];
btnDetail.frame = CGRectMake(0,0,100,100);
[btnDetail addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventAllTouchEvents];
[self.imageView addSubview:btnDetail];
Run Code Online (Sandbox Code Playgroud)
当我将它添加到UIImageVIew时按钮无法单击,但如果我不将它添加到UIImageView,它可以正常工作.请有人帮帮我
如何使用像http://img.abc.com/noPhoto4530.gif这样的链接创建带有图像的UIImageView ?
我有一个UIImageView我想要淡入的东西.
有没有办法在基础上启用它UIViewController?
我已经C# .NET为MonoTouch用户翻译了最简单的答案,尽管它们都有效:
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
UIView.BeginAnimations ("fade in");
UIView.SetAnimationDuration (1);
imageView.Alpha = 1;
UIView.CommitAnimations ();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个框架,保留我在项目中使用的一些常用代码.我找到了在线教程并设法创建了一个框架,但我仍然有一个与资源相关的问题(xib,图像等).
假设我有MainViewController.xib一个UIImageView使用a test.png.所有这些都在我的框架包中.
当我在另一个项目中使用框架时,我将其添加到"Copy Bundle Resources"构建阶段.问题是xib只能使用类似的路径访问dummy.framework/Resources/MainViewController.xib,并且UIImageView内部无法加载test.png.
似乎UIImageView将尝试从bundle的根目录加载png,而不是从也存储xib的相对文件夹加载.
有没有人设法创建一个包含代码和资源的框架并在另一个项目中使用它?
我在IB的视图上放了一个UIImageView控件.控件的大小只是我决定的,非常随机的大小真正我想做的是每当我将image属性设置为新图像时自动调整大小的控件.我希望它实际调整大小到图像的大小.可以自动完成吗?没有任何代码干预?如果不是 - 在这种情况下最好的方法是什么?
今天发生的事情很奇怪.我将图像加载到ImageView中,即使ImageView的大小没有改变,我也能看到图像正确显示.这干扰了我在ImageView上抓取用户触摸的意图.用户触摸实际图像,但由于图像的某些部分位于ImageView的外部(这是奇怪的部分) - 点映射变得疯狂有人能想到对此的任何解释吗?
谢谢
我刚刚将用于缓存图像的代码从EGOImageCache更改为SDWebView.不幸的是我不知道如何设置自定义HTTP标头,因为我必须发送身份验证才能获取图像.使用EGOImageCache很容易,因为我已经在适当的地方扩展了NSURLRequest.但是我不知道如何使用SDWebView.framework来做到这一点.我看到标题,我在SDWebImageDownloader.h中找到了包含的方法
/**
* Set a value for a HTTP header to be appended to each download HTTP request.
*
* @param value The value for the header field. Use `nil` value to remove the header.
* @param field The name of the header field to set.
*/
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
/**
* Returns the value of the specified HTTP header field.
*
* @return The value associated with the header field field, or `nil` if there is no …Run Code Online (Sandbox Code Playgroud) 我的代码大部分都适用.
我错过了什么?
这是我的代码:
cell.imageView.layer.cornerRadius = cell.imageView.frame.size.width / 2.0;
cell.imageView.layer.borderWidth = 3.0;
cell.imageView.layer.borderColor = [UIColor colorWithRed:157.0/255.0 green:34.0/255.0 blue:53.0/255.0 alpha:1.0]
.CGColor;
cell.imageView.clipsToBounds = YES;
NSDictionary *tweet = (self.results)[indexPath.row];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSString * imageString = [tweet valueForKeyPath:@"user.profile_image_url"];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:imageString]];
if (imageData != nil)
{
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image = [UIImage imageWithData: imageData];
[cell setNeedsLayout];
});
}
});
Run Code Online (Sandbox Code Playgroud)
编辑 ----代码在cellForRowAtIndexPath中
编辑二
我看到的另一个问题是当我滚动时图像会发生变化.
我该如何防止这种情况?
我一直在用这种方法转换UIView成UIImage.即视图的屏幕快照 -
@interface UIView(Extended)
- (UIImage *) imageByRenderingView;
@end
@implementation UIView(Extended)
- (UIImage *)imageByRenderingView
{
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
@end
Run Code Online (Sandbox Code Playgroud)
要使用它,我这样做 -
UIImage *currImage = [self.view imageByRenderingView];
这给出了整个图像的表示UIView.现在我想要2个图像,一个是上半部分UIView,另一个是下半部分.我怎么做?
我已经创建了一个静态库和一个资源包,用于在多个项目中重用代码和资产.
在静态库中,我有一个管理器类,其唯一目的是创建其他的UIViewControllers,其视图是从.xib文件创建的(使用常用initWithNibName:bundle:方法).
在Interface Builder中创建视图时,图像显示正确.但是,当我在模拟器上运行应用程序时,我收到此错误:
Could not load the "<image_name.png>" image referenced from a nib in the
bundle with identifier "com.<my_company>.<app_identifer>"
Run Code Online (Sandbox Code Playgroud)
经过几个小时的研磨,我终于检查了资源包,发现.png文件不在其中!相反,相反名称的.tiff文件(不包括@ 2x版本).
所有图像都包含在捆绑包的构建阶段,在复制包资源下,我已经在其他iOS项目中使用了这些图像(因此它们没有被破坏).
还有其他人经历过这个吗?是否可以安全地假设图像将始终作为.tiff添加到包中?(如果是这样,将界面生成器中的图像名称更改为.tiff是否安全?)或者我在这里做错了什么?
感谢您的帮助.
uiimageview ×10
ios ×7
iphone ×5
objective-c ×3
ipad ×2
uiimage ×2
frameworks ×1
fullscreen ×1
http-headers ×1
macos ×1
point ×1
resize ×1
sdwebimage ×1
touches ×1
uibutton ×1
uiscrollview ×1
uitableview ×1
uiview ×1
xamarin.ios ×1
xib ×1