【发布时间】:2014-08-06 09:53:34
【问题描述】:
我正在使用 CGRect 创建一个图像框架。我想将创建的矩形居中。
我在此处以及 Apple 文档中查看了执行此操作的最佳方法,并找到了获取中心坐标的 CGRectGetMidY 和 CGRectGetMidX。
当我尝试在自己的代码中实现这一点时,我遇到了问题。我在 UIIMageView 类型的对象上找不到属性大小错误
#import "MyViewController.h"
@interface MyViewController ()
@end
@implementation MyViewController
@synthesize mySignatureImage;
@synthesize lastContactPoint1, lastContactPoint2, currentPoint;
@synthesize imageFrame;
@synthesize fingerMoved;
@synthesize navbarHeight;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
CGRect mySignatureImageFrame = CGRectMake(
CGRectGetMidX(self.view.frame) - (mySignatureImage.size.width/ 2.0),
CGRectGetMidY(self.view.frame) - (mySignatureImage.size.height / 2.0),
image.size.width,
image.size.height);
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController <UIAlertViewDelegate>
@property (nonatomic, strong) UIImageView *mySignatureImage;
@property (nonatomic, assign) CGPoint lastContactPoint1, lastContactPoint2, currentPoint;
@property (nonatomic, assign) CGRect imageFrame;
@property (nonatomic, assign) BOOL fingerMoved;
@property (nonatomic, assign) float navbarHeight;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
【问题讨论】:
-
您希望图像帧有多大?
-
imageView.center = CGPointMake(CGRectGetMidX(self.view.frame), CGRectGetMidY(self.view.frame)); -
它的意思是足够大,用户可以写签名,非常大。我玩过数字和大小,但居中是导致问题的原因。 @Droppy
-
@KudoCC 感谢您的回复,试过了,我得到一个未知类型名称“imageView”你的意思是 UIIMageView 错误
-
@aramirez imageView 是
UIImageView。
标签: ios objective-c uiimage cgrect