- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
就像我最近遇到的大多数问题一样,我认为这是一个语法问题。我知道我想做什么,但我不知道如何写。我正在尝试创建一个拼图类型的应用程序。 CGPoints 表示每个图像应位于的中心点。
不过,我在声明/初始化 CGPoints 数组时遇到了问题。下面是代码:
.h 文件
#import <UIKit/UIKit.h>
@interface DSAAssignmentViewController2 : UIViewController
@property (weak, nonatomic) NSString *passedData;
@property (weak, nonatomic) IBOutlet UILabel *lblDisplayPreviousInput;
@property (weak, nonatomic) IBOutlet UIImageView *imgOriginal;
@property (weak, nonatomic) IBOutlet UIImageView *img1;
@property (weak, nonatomic) IBOutlet UIImageView *img2;
@property (weak, nonatomic) IBOutlet UIImageView *img3;
@property (weak, nonatomic) IBOutlet UIImageView *img4;
@property (weak, nonatomic) IBOutlet UIImageView *img5;
@property (weak, nonatomic) IBOutlet UIImageView *img6;
@property (weak, nonatomic) IBOutlet UIImageView *img7;
@property (weak, nonatomic) IBOutlet UIImageView *img8;
@property (weak, nonatomic) IBOutlet UIImageView *img9;
@property (weak, nonatomic) IBOutlet UIImageView *img10;
@property (weak, nonatomic) IBOutlet UIImageView *img11;
@property (weak, nonatomic) IBOutlet UIImageView *img12;
@property (weak, nonatomic) IBOutlet UIImageView *img13;
@property (weak, nonatomic) IBOutlet UIImageView *img14;
@property (weak, nonatomic) IBOutlet UIImageView *img15;
@property (weak, nonatomic) IBOutlet UIImageView *img16;
@property (weak, nonatomic) IBOutlet UIImageView *img17;
@property (weak, nonatomic) IBOutlet UIImageView *img18;
@property (weak, nonatomic) IBOutlet UIImageView *img19;
@property (weak, nonatomic) IBOutlet UIImageView *img20;
@property (weak, nonatomic) IBOutlet UIImageView *img21;
@property (weak, nonatomic) IBOutlet UIImageView *img22;
@property (weak, nonatomic) IBOutlet UIImageView *img23;
@property (weak, nonatomic) IBOutlet UIImageView *img24;
@property (weak, nonatomic) IBOutlet UIImageView *img25;
@property (weak, nonatomic) IBOutlet UIImageView *img26;
@property (weak, nonatomic) IBOutlet UIImageView *img27;
@property (weak, nonatomic) IBOutlet UIImageView *img28;
@property (weak, nonatomic) IBOutlet UIImageView *img29;
@property (weak, nonatomic) IBOutlet UIImageView *img30;
@property (weak, nonatomic) IBOutlet UIImageView *img31;
@property (weak, nonatomic) IBOutlet UIImageView *img32;
@property (weak, nonatomic) IBOutlet UIImageView *img33;
@property (weak, nonatomic) IBOutlet UIImageView *img34;
@property (weak, nonatomic) IBOutlet UIImageView *img35;
@property (weak, nonatomic) IBOutlet UIImageView *img36;
@property (weak, nonatomic) IBOutlet UIImageView *img37;
@property (weak, nonatomic) IBOutlet UIImageView *img38;
@property (weak, nonatomic) IBOutlet UIImageView *img39;
@property (weak, nonatomic) IBOutlet UIImageView *img40;
@property (strong, nonatomic) NSArray *imageViews;
@property CGPoint *holder1;
@property CGPoint *holder2;
@property CGPoint *holder3;
@property CGPoint *holder4;
@property CGPoint *holder5;
@property CGPoint *holder6;
@property CGPoint *holder7;
@property CGPoint *holder8;
@property (strong, nonatomic) NSMutableArray *holders;
@end
.m文件
#import "DSAAssignmentViewController2.h"
@interface DSAAssignmentViewController2 ()
@end
@implementation DSAAssignmentViewController2
@synthesize lblDisplayPreviousInput;
@synthesize imgOriginal;
@synthesize img1;
@synthesize img2;
@synthesize img3;
@synthesize img4;
@synthesize img5;
@synthesize img6;
@synthesize img7;
@synthesize img8;
@synthesize img9;
@synthesize img10;
@synthesize img11;
@synthesize img12;
@synthesize img13;
@synthesize img14;
@synthesize img15;
@synthesize img16;
@synthesize img17;
@synthesize img18;
@synthesize img19;
@synthesize img20;
@synthesize img21;
@synthesize img22;
@synthesize img23;
@synthesize img24;
@synthesize img25;
@synthesize img26;
@synthesize img27;
@synthesize img28;
@synthesize img29;
@synthesize img30;
@synthesize img31;
@synthesize img32;
@synthesize img33;
@synthesize img34;
@synthesize img35;
@synthesize img36;
@synthesize img37;
@synthesize img38;
@synthesize img39;
@synthesize img40;
@synthesize passedData;
@synthesize imageViews;
@synthesize holder1;
@synthesize holder2;
@synthesize holder3;
@synthesize holder4;
@synthesize holder5;
@synthesize holder6;
@synthesize holder7;
@synthesize holder8;
@synthesize holders;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// make jigsaw piece holders
//create 8 points where the jigsaw pieces (images) will be placed
CGPoint holder1 = CGPointMake(60, 644);
CGPoint holder2 = CGPointMake(140, 644);
CGPoint holder3 = CGPointMake(220, 644);
CGPoint holder4 = CGPointMake(300, 644);
CGPoint holder5 = CGPointMake(380, 644);
CGPoint holder6 = CGPointMake(460, 644);
CGPoint holder7 = CGPointMake(540, 644);
CGPoint holder8 = CGPointMake(620, 644);
// set up array of cgpoints
holders = [NSMutableArray arrayWithObjects:[NSValue valueWithCGPoint: holder1],[NSValue valueWithCGPoint: holder2], [NSValue valueWithCGPoint: holder3], [NSValue valueWithCGPoint: holder4], [NSValue valueWithCGPoint: holder5], [NSValue valueWithCGPoint: holder6], [NSValue valueWithCGPoint: holder7], [NSValue valueWithCGPoint: holder8], nil];
// set up array of images
imageViews = [NSArray arrayWithObjects:img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14, img15, img16, img17, img18, img19, img20, img21, img22, img23, img24, img25, img26, img27, img28, img29, img30, img31, img32, img33, img34, img35, img36, img37, img38, img39, img40, nil];
NSString *welcomeMessage = [NSString stringWithFormat:@"Welcome %@", passedData];
UIAlertView *alert = [[UIAlertView alloc] //show alert box with option to play or exit
initWithTitle: welcomeMessage
message:@"Once you press \"Play\" the timer will start. Good luck!"
delegate:self
cancelButtonTitle:@"I want out!"
otherButtonTitles:@"Play",nil];
[alert show];
NSLog(@"x-coord: %f, y-coord: %f", holder1.x, holder1.y);
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//location of current touch
CGPoint location = [touch locationInView:self.view];
UIView *touchedView = [touch view];
if ([imageViews indexOfObject:touchedView] != NSNotFound) {
// not not found means found!
[self animateFirstTouch:touchedView withLocation:location];
} else {
return;
}
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//location of current touch
CGPoint location = [touch locationInView:self.view];
UIView *touchedView = [touch view];
[self animateReleaseTouch:touchedView withLocation:location];
}
- (void)viewDidUnload
{
[self setLblDisplayPreviousInput:nil];
[self setImgOriginal:nil];
[self setImg1:nil];
[self setImg2:nil];
[self setImg3:nil];
[self setImg4:nil];
[self setImg5:nil];
[self setImg6:nil];
[self setImg7:nil];
[self setImg8:nil];
[self setImg9:nil];
[self setImg10:nil];
[self setImg11:nil];
[self setImg12:nil];
[self setImg13:nil];
[self setImg14:nil];
[self setImg15:nil];
[self setImg16:nil];
[self setImg17:nil];
[self setImg18:nil];
[self setImg19:nil];
[self setImg20:nil];
[self setImg21:nil];
[self setImg22:nil];
[self setImg23:nil];
[self setImg24:nil];
[self setImg25:nil];
[self setImg26:nil];
[self setImg27:nil];
[self setImg28:nil];
[self setImg29:nil];
[self setImg30:nil];
[self setImg31:nil];
[self setImg32:nil];
[self setImg33:nil];
[self setImg34:nil];
[self setImg35:nil];
[self setImg36:nil];
[self setImg37:nil];
[self setImg38:nil];
[self setImg39:nil];
[self setImg40:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(void) animateFirstTouch:(UIImageView *)image withLocation:(CGPoint)location {
image.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
image.transform = CGAffineTransformMakeScale(1.25, 1.25);
[UIView commitAnimations];
}
-(void) animateReleaseTouch:(UIImageView *)image withLocation:(CGPoint)location {
image.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
image.transform = CGAffineTransformMakeScale(1.0, 1.0);
[UIView commitAnimations];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
我不知道这是否有点困惑。正如您所看到的,我一开始只使用了 8 个“支架”,这些是代表拼图 block 应放置中心的 CGPoint。
最佳答案
博尔登是正确的。通过将它们声明为属性并合成它们,您已经创建了一大堆 CGPoint 指针变量。但是,然后在您的 -viewDidLoad
方法中,您声明 CGPoint 结构(而不是 CGPoint 指针),所有这些都与您合成的属性具有相同的名称。
从代码中判断,根本不需要 holderN
属性。事实上,您甚至不需要 -viewDidLoad
方法中的holderN 变量。你可以很容易地摆脱这样的事情:
- ( void )viewDidLoad
{
holders = [ NSMutableArray arrayWithObjects:
[ NSValue valueWithCGPoint: CGPointMake(60, 644) ],
...,
[ NSValue valueWithCGPoint: CGPointMake(N, N) ],
nil ];
...
}
不过,对点坐标进行硬编码的设计很糟糕。最好的选择是将坐标放入 plist 中,您可以根据需要加载该坐标并将其填充到数组中。这意味着调整坐标只需编辑 plist 即可。无需重新编译。
关于objective-c - 声明/初始化 CGPoints 数组时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9994999/
我正在尝试创建一个包含 int[][] 项的数组 即 int version0Indexes[][4] = { {1,2,3,4}, {5,6,7,8} }; int version1Indexes[
我有一个整数数组: private int array[]; 如果我还有一个名为 add 的方法,那么以下有什么区别: public void add(int value) { array[va
当您尝试在 JavaScript 中将一个数组添加到另一个数组时,它会将其转换为一个字符串。通常,当以另一种语言执行此操作时,列表会合并。 JavaScript [1, 2] + [3, 4] = "
根据我正在阅读的教程,如果您想创建一个包含 5 列和 3 行的表格来表示这样的数据... 45 4 34 99 56 3 23 99 43 2 1 1 0 43 67 ...它说你可以使用下
我通常使用 python 编写脚本/程序,但最近开始使用 JavaScript 进行编程,并且在使用数组时遇到了一些问题。 在 python 中,当我创建一个数组并使用 for x in y 时,我得
我有一个这样的数组: temp = [ 'data1', ['data1_a','data1_b'], ['data2_a','data2_b','data2_c'] ]; // 我想使用 toStr
rent_property (table name) id fullName propertyName 1 A House Name1 2 B
这个问题在这里已经有了答案: 关闭13年前。 Possible Duplicate: In C arrays why is this true? a[5] == 5[a] array[index] 和
使用 Excel 2013。经过多年的寻找和适应,我的第一篇文章。 我正在尝试将当前 App 用户(即“John Smith”)与他的电子邮件地址“jsmith@work.com”进行匹配。 使用两个
当仅在一个边距上操作时,apply 似乎不会重新组装 3D 数组。考虑: arr 1),但对我来说仍然很奇怪,如果一个函数返回一个具有尺寸的对象,那么它们基本上会被忽略。 最佳答案 这是一个不太理
我有一个包含 GPS 坐标的 MySQL 数据库。这是我检索坐标的部分 PHP 代码; $sql = "SELECT lat, lon FROM gps_data"; $stmt=$db->query
我需要找到一种方法来执行这个操作,我有一个形状数组 [批量大小, 150, 1] 代表 batch_size 整数序列,每个序列有 150 个元素长,但在每个序列中都有很多添加的零,以使所有序列具有相
我必须通过 url 中的 json 获取文本。 层次结构如下: 对象>数组>对象>数组>对象。 我想用这段代码获取文本。但是我收到错误 :org.json.JSONException: No valu
enter code here- (void)viewDidLoad { NSMutableArray *imageViewArray= [[NSMutableArray alloc] init];
知道如何对二维字符串数组执行修剪操作,例如使用 Java 流 API 进行 3x3 并将其收集回相同维度的 3x3 数组? 重点是避免使用显式的 for 循环。 当前的解决方案只是简单地执行一个 fo
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我有来自 ASP.NET Web 服务的以下 XML 输出: 1710 1711 1712 1713
如果我有一个对象todo作为您状态的一部分,并且该对象包含数组列表,则列表内部有对象,在这些对象内部还有另一个数组listItems。如何更新数组 listItems 中 id 为“poi098”的对
我想将最大长度为 8 的 bool 数组打包成一个字节,通过网络发送它,然后将其解压回 bool 数组。已经在这里尝试了一些解决方案,但没有用。我正在使用单声道。 我制作了 BitArray,然后尝试
我们的数据库中有这个字段指示一周中的每一天的真/假标志,如下所示:'1111110' 我需要将此值转换为 boolean 数组。 为此,我编写了以下代码: char[] freqs = weekday
我是一名优秀的程序员,十分优秀!