好吧我想添加一个UIImageView作为子视图,然后在启动画面工作的几秒钟后删除它.我找到了三种不同的方法,但根据Objective-C和Apple,我无法理解哪种方法是最好的方法.
以下是三种不同的方法:
1)在我的MyAppDelegate.h中
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
MyViewController *myViewController;
UIImageView *myImageView;
}
@property (nonatomic, retain) IBOutlet MyViewController *myViewController;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
Run Code Online (Sandbox Code Playgroud)
在MyAppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
myImageView =[[UIImageView alloc] initWithFrame:CGRectMake(0.0,0.0,self.window.frame.size.width,self.window.frame.size.height)];
myImageView.image=[UIImage imageNamed:@"Yoga.png"];
[self.window addSubview:myImageView ];
[self.window bringSubviewToFront:myImageView];
[self performSelector:@selector(removeImage) withObject:nil afterDelay:2.5];
return YES;
}
-(void) removeImage
{
[myImageView removeFromSuperview];
[myImageView release];
[self.window addSubview:myViewController.view];
[self.window makeKeyAndVisible];
}
Run Code Online (Sandbox Code Playgroud)
2)在第二种方法中:
In my MyAppDelegate.h
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
MyViewController *myViewController;
UIImageView *myImageView;
}
@property …Run Code Online (Sandbox Code Playgroud) 我对如何做我需要的东西感到很困惑!任何帮助非常感谢!我有一个透明的图像叠加层,后面有另一个图像,它附有一个UIPanGestureRecognizer和一个UIPinchGestureRecognizer.顶部图像具有完全透明的中间,用作"玻璃"视图.我试图将底部图像裁剪为基于平移和捏合的"玻璃"部分.(见下面的图片,看看我在说什么)我已经成功地处理了平底锅作物,但是在应用捏合时也有问题正确裁剪.
我没有使用snapshotViewAfterScreenUpdates.
这是我到目前为止的代码:
UIImage *snapshotImage;
/* draw the image of all the views below our view */
UIGraphicsBeginImageContextWithOptions(self.pendantImageView.bounds.size, NO, 0);
BOOL successfulDrawHierarchy = [self.pendantImageView drawViewHierarchyInRect:self.pendantImageView.bounds afterScreenUpdates:YES];
if ( successfulDrawHierarchy ) {
snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
} else {
NSLog(@"drawViewHierarchyInRect:afterScreenUpdates: failed - there's nothing to draw...");
}
UIGraphicsEndImageContext();
UIImage *croppedImage;
if ( successfulDrawHierarchy ) {
/* calculate the coordinates of the rectangle we're interested in within the returned image */
CGRect cropRect = CGRectOffset(pendantFrame, - self.pendantImageView.frame.origin.x, - self.pendantImageView.frame.origin.y);
/* draw the cropped …Run Code Online (Sandbox Code Playgroud) objective-c uiimageview ios uipangesturerecognizer uipinchgesturerecognizer
理想情况下,NSCoding兼容类将使用encodeWithCoder:和initWithCoder按预期工作:(至少我认为直到最近),开发人员不必担心例程内部的内容(除非我对NSCoding兼容类的想法完全搞砸了) !)
UIImageView类符合NSCoding.所以我不应该打扰如何使用NSKeyedArchiver和NSKeyedUnarchiver类对它进行序列化/反序列化.但每次我尝试编码UIImageView对象时,都会收到UIImage无法识别的错误:encodeWithCoder:method.
现在UIImageView内部使用UIImage对象.但编码是否应该自己处理?
或者文档中指定的NSCoding合规性是否让用户知道他们可以实现initWithCoder和encodeWithCoder方法?
有人可以帮我澄清一下!我很困惑!
我有一个图像数组加载到UIImageView中,我通过一个循环动画.显示图像后,我想@selector调用一个以关闭当前视图控制器.使用以下代码可以很好地动画图像:
NSArray * imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"HowTo1.png"],
[UIImage imageNamed:@"HowTo2.png"],
nil];
UIImageView * instructions = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
instructions.animationImages = imageArray;
[imageArray release];
instructions.animationDuration = 16.0;
instructions.animationRepeatCount = 1;
instructions.contentMode = UIViewContentModeBottomLeft;
[instructions startAnimating];
[self.view addSubview:instructions];
[instructions release];
Run Code Online (Sandbox Code Playgroud)
16秒后,我想要一个方法来调用.我查看了UIView类方法,setAnimationDidStopSelector:但我无法使用它来处理当前的动画实现.有什么建议?
谢谢.
在我的应用程序中,我UITextView在文本视图下方有一个按钮,可以UITextView在编辑时插入照片.
我的要求是用户用户能够在其中编辑文本,并在需要时插入图像.
与StackOverflow的应用程序类似UITextView:

如何通过在手指上滑动来擦除前面UIImage上的内容并显示UIView背面的UIImage.
我曾使用以下代码- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 擦除前图像:
-(void)eraseDrawingContents
{
UIGraphicsBeginImageContext(frontImage.frame.size);
[frontImage.image drawInRect:CGRectMake(0, 0, frontImage.frame.size.width, frontImage.frame.size.height)];
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 25.0);
CGContextSetShadowWithColor(UIGraphicsGetCurrentContext(), CGSizeMake(0, 0), 50, [[UIColor whiteColor]CGColor]);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, lastPoint.x, lastPoint.y);
CGPathAddLineToPoint(path, nil, currentPoint.x, currentPoint.y);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
CGContextAddPath(UIGraphicsGetCurrentContext(), path);
CGContextStrokePath(UIGraphicsGetCurrentContext());
frontImage.image = UIGraphicsGetImageFromCurrentImageContext();
CGContextRestoreGState(UIGraphicsGetCurrentContext());
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
Run Code Online (Sandbox Code Playgroud)
我实现了以下输出.
但我需要像这样的输出.

我们如何实现这一功能?
请帮我.
我有一个目标动作,当按下按钮时,我验证UITextField:
// Get the text from the UITextField
NSString *nameStr = _name.text;
_name.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error.png"]];
[self.view addSubview:_name];
if (nameStr.length == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Name"
message:@"You must enter a name."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
Run Code Online (Sandbox Code Playgroud)
我UITextField被添加到视图中,viewDidLoad如下所示:
[self.view addSubview:_name];
Run Code Online (Sandbox Code Playgroud)
如何UIImageView显示rightView ?
我正在编写一个应用程序iOS 7.0+,我想使用新功能imageWithRenderingMode.我有一个使用此代码的地图注释:
-(MKAnnotationView*)annotationView {
MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:self reuseIdentifier:@"AnnotationIdentifier"];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image = [[UIImage imageNamed:@"star"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.tintColor = [UIColor redColor];
return annotationView;
}
Run Code Online (Sandbox Code Playgroud)
我原本以为我的针脚是红色的,但是保持黑色,只有标注(i)图标变成红色.

我试图设置self.view.tintColor和self.mapView.tintColor我的,ViewController但这也不起作用.如何将此引脚变为红色?
我正在尝试将用户上传的图像从一个UIImageView移动到另一个View Controller上的另一个UIImageView.我可以让用户上传图像并将其保存在第一个UIImageView中,但在按下"发布"按钮后,下一个视图控制器上的UIImageView仍为空白.
注意:browsingImage是第二个视图控制器上的UIImageView的名称(目标UIImageView)
任何帮助将不胜感激!
@IBAction func cameraButton(sender: AnyObject) {
addNewPicture()
}
func addNewPicture() {
let picker = UIImagePickerController()
picker.allowsEditing = true
picker.delegate = self
presentViewController(picker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
postingImage.image = image
self.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func postButton(sender: AnyObject) {
performSegueWithIdentifier("toBrowsePage", sender: nil)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "toBrowsePage" {
var itemToAdd = segue.destinationViewController as! …Run Code Online (Sandbox Code Playgroud) 启用接近传感器时,我无法让设备使用后视摄像头拍摄图像.我不希望相机预览显示,只是希望设备拍摄照片并将其显示在imageView中.我有接近传感器工作,我正在使用接近传感器启用imagePicker.takePicture()时拍摄图像,但这似乎不起作用.我可以使用什么方法/函数以编程方式拍摄没有用户输入的图片.
到目前为止这是我的代码:
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet var imageView: UIImageView!
var imagePicker: UIImagePickerController!
//*The function in question*
func proximityChanged(notification: NSNotification) {
let device = notification.object as? UIDevice
if device?.proximityState == true {
print("\(device) detected!")
Run Code Online (Sandbox Code Playgroud) uiimageview ×10
ios ×7
objective-c ×6
iphone ×5
swift ×2
animation ×1
cgcontext ×1
image ×1
ios7 ×1
ipad ×1
mkannotation ×1
nscoding ×1
subview ×1
uibutton ×1
uikit ×1
uitextfield ×1
uitextview ×1
uiview ×1