开发者

How to access subclassed UIView's properties?

I'm having problem accessing the usual properties like frame, bounds, origin, size, etc etc. Within my subclassed UIView, I'm trying to edit the frame/bounds when the user presses something.

I keep getting this error 'frame' undeclared (first use in this function).

EyeView.h

 #import <UIKit/UIKit.h>

@interface EyeView : UIView {
    CGFloat minWidth;
    CGFloat minHeight;
    bool touchInWindow, touchTopLeft, touchTop, touchTopRight, touchLeft, touchRight, touchBottomLeft, touchBottom, touchBottomRight;   
    bool dragging;
}

@property CGFloat minWidth;
@property CGFloat minHeight;

- (void)checkTouchedWhere:(NSSet *)touches;

@end

Eye开发者_如何学CView.m

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    if (touches.count == 1){
        if (dragging == TRUE){
                CGPoint prevPoint1 = [[[touches allObjects] objectAtIndex:0] previousLocationInView:self];
                CGPoint currPoint1 = [[[touches allObjects] objectAtIndex:0] locationInView:self];
            CGFloat differencex = currPoint1.x - prevPoint1.x;
            CGFloat differencey = currPoint1.y - prevPoint1.y;
            frame.origin.x += differencex;
            frame.origin.y += differencey;
            [self setNeedsDisplay];

        }
    }
}


self.frame is working with Xcode 3.2.3 (remember is case-sensitive)

self.view doesn't exist in UIView (it exists in UIViewController), so self.view.frame won't work.

Try [self frame] instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜