English 中文(简体)
2. 使用非正常的 but子的简单方式
原标题:Simple way of using irregular shaped buttons

我终于获得我的主要信息释放(TapAction MMO——检查它;-)和Im,现在致力于扩大它。

为了做到这一点,我需要有一个四座 se子圈子的圈子,这些 but子将基本上处于 quarters状态。 我得出这样的结论,即需要构造四张图像,每季度一个图像,但由于需要直观图像形成一米,最后出现一些重叠,尽管重叠将是透明的。

What s the best way of getting this to work? I need something really simple really, I ve looked at this http://iphonedevelopment.blogspot.com/2010/03/irregularly-shaped-uibuttons.html

在此之前,但尚未成功完成这项工作。 谁能够提供一些建议?

如果情况出现任何变化,就将直升机部署到3号。 X框架(如果为iPad提供4.2条,将下降4.2条)

最佳回答

I can t see, why overlapping is needed.
Just create 4 buttons and give each one a slice of your image.

<edit after comment<>

great Project。 一个例子就是你想要做什么。

它通过将甲型六氯环己烷的沥青价值纳入超成文法。

http://www.un.org

- (UIColor *)colorAtPixel:(CGPoint)point {
    // Cancel if point is outside image coordinates
    if (!CGRectContainsPoint(CGRectMake(0.0f, 0.0f, self.size.width, self.size.height), point)) {
        return nil;
    }


    // Create a 1x1 pixel byte array and bitmap context to draw the pixel into.
    // Reference: http://stackoverflow.com/questions/1042830/retrieving-a-pixel-alpha-value-for-a-uiimage
    NSInteger pointX = trunc(point.x);
    NSInteger pointY = trunc(point.y);
    CGImageRef cgImage = self.CGImage;
    NSUInteger width = self.size.width;
    NSUInteger height = self.size.height;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    int bytesPerPixel = 4;
    int bytesPerRow = bytesPerPixel * 1;
    NSUInteger bitsPerComponent = 8;
    unsigned char pixelData[4] = { 0, 0, 0, 0 };
    CGContextRef context = CGBitmapContextCreate(pixelData, 
                                                 1,
                                                 1,
                                                 bitsPerComponent, 
                                                 bytesPerRow, 
                                                 colorSpace,
                                                 kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGColorSpaceRelease(colorSpace);
    CGContextSetBlendMode(context, kCGBlendModeCopy);

    // Draw the pixel we are interested in onto the bitmap context
    CGContextTranslateCTM(context, -pointX, pointY-(CGFloat)height);
    CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, (CGFloat)width, (CGFloat)height), cgImage);
    CGContextRelease(context);

    // Convert color values [0..255] to floats [0.0..1.0]
    CGFloat red   = (CGFloat)pixelData[0] / 255.0f;
    CGFloat green = (CGFloat)pixelData[1] / 255.0f;
    CGFloat blue  = (CGFloat)pixelData[2] / 255.0f;
    CGFloat alpha = (CGFloat)pixelData[3] / 255.0f;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
问题回答

Ski浅,只是对你认为包含圈子的触动作出反应。

• 为你们想要捕捉的每个地区建立共同愿景,在贵方论坛获得接触点时,检查在通道内的成员资格。

在此,我将如何处理这一问题:(我没有测试过这一法典,而这个综合体可能并不正确,但这是一般的想法)

(1) 利用PS或你喜欢的图像制作应用程序,在季度圈子中形成一只平方。 加入你的XCode项目。

2) 致信于律师公会。 《联邦法典》中含有一层内容。

self.myView = [[UIView alloc] initWithRect:CGRectMake(10.0, 10.0, 100.0, 100,0)];
[myView.layer setContents:(id)[UIImage loadImageNamed:@"my.png"]];

3) 在你感兴趣的《调查意见》中,创建描述本区域的《卫生政策》。

self.quadrantOnePath = CGPathCreateMutable();
CGPathMoveToPoint(self.quadrantOnePath, NULL, 50.0, 50.0);
CGPathAddLineToPoint(self.quadrantOnePath, NULL, 100.0, 50.0);
CGPathAddArc(self.quadrantOnePath, NULL, 50.0, 50.0, 50.0, 0.0, M_PI2, 1);
CGPathCloseSubpath(self.quadrantOnePath);

// create paths for the other 3 circle quadrants too!

4) 添加一个UIGestureRecognizer和听众/观察员,供作主

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[tapRecognizer setNumberOfTapsRequired:2]; // default is 1

5) 在主机援引其目标选择时

- (void)handleGesture:(UIGestureRecognizer *) recognizer {

  CGPoint touchPoint = [recognizer locationOfTouch:0 inView:self.myView];
  bool processTouch = CGPathContainsPoint(self.quadrantOnePath, NULL, touchPoint, true);

  if(processTouch) {
     // call your method to process the touch
  }
}

不要忘记酌情释放所有东西——利用CGPathRelease释放道路。

另一种想法: 如果你用来代表你的圈子的图象只是一个装满的颜色(即没有图象、层效应等),那么你也可以使用《国际宇宙航行联合会》的代谢法中你所创造的道路,来吸引 qua子。 这将解决上述办法的一个缺陷:在图形和用于检查线的通道之间没有紧密结合。 也就是说,如果你用图象换成不同的图象,改变图象的大小等,那么你用来检查点的路子就会脱离yn。 可能是一部高额的法典。

Here s an awesome project that solves the problem of irregular shaped buttons so easily: http://christinemorris.com/2011/06/ios-irregular-shaped-buttons/





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签